当仅在没有陷波功能的电话上录制和工作时,Media Recorder变黑

时间:2019-07-11 14:45:39

标签: android surfaceview mediarecorder

我正在使用可记录的表面进行视频记录。我正在尝试准备设置所有属性以及videoSize宽度和高度的媒体记录器。它适用于所有手机,但不适用于带槽口的手机。我正在调整身高,有时可以看到预览。但是,如果我通过设置displayMetrics的显示高度和宽度将其默认设置为所有设备使用,则它适用于某些手机,不适用于我的PIXEL3 XL手机。请帮忙。

这就是我使用init方法设置媒体记录器的方式。

private void resetVideoFragment() {
        logger.info("Resetting Video Fragment ");
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        int height = displayMetrics.heightPixels;
        int width = displayMetrics.widthPixels;

        if (videoRenderer == null) {
            videoRenderer = new Renderer(this, width, height);
        }
        setupVideoFragment(videoRenderer);
        viewHolder.liveSurfaceView.resume();
        videoFile = getVideoFile();
        try {
            viewHolder.liveSurfaceView.initRecorder(videoFile, width, height, (mr, what, extra) -> {
                logger.error("Media Recorder error " + " what: " + what + " extra: " + extra);
            }, (mr, what, extra) -> {
                logger.error("Media Recorder Info " + " what: " + what + " extra: " + extra);
            });
        } catch (IOException iox) {
            logger.error("Couldn't re-init recording " + iox);
        }
    }

这是我的init mediarecorder方法的样子

public void initRecorder(File saveToFile, int displayWidth, int displayHeight,
                             int orientationHint, MediaRecorder.OnErrorListener errorListener,
                             MediaRecorder.OnInfoListener infoListener) {

        MediaRecorder mediaRecorder = new MediaRecorder();
        mediaRecorder.setOnInfoListener(infoListener);
        mediaRecorder.setOnErrorListener(errorListener);

        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mediaRecorder.setInputSurface(mSurface);
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        mediaRecorder.setAudioSamplingRate(44100);
        mediaRecorder.setAudioEncodingBitRate(96000);

        mediaRecorder.setVideoSize(displayWidth, displayHeight);
(On phone which doesn't work If i try to tweak this height and width
 it able to shows preview if i increase more number to it and
 it throws to the error i was talking about while recording
How to make it work for all the phones ?)

        mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);

        // original setting-- resulted in a huge file in just a few seconds!!
//        mediaRecorder.setVideoEncodingBitRate(12000000);
        mediaRecorder.setVideoEncodingBitRate(7500000);
        mediaRecorder.setVideoFrameRate(30);
        mediaRecorder.setOrientationHint(orientationHint);

        mediaRecorder.setOutputFile(saveToFile.getPath());
        mediaRecorder.setPreviewDisplay(mSurface);
        try {
            mediaRecorder.prepare();
        } catch (IOException e) {
            logger.error("IO Exception on Media Recorder init method: " + e.getLocalizedMessage());
        }

        mMediaRecorder = mediaRecorder;

    }

错误代码:100额外:2 什么:268435556额外:录制时为-1007

0 个答案:

没有答案