privatevoidsetupMediaRecorder(VideoOutputConfigmode){recorderSurface=MediaCodec.createPersistentInputSurface();mediaRecorder=createRecorder(mode.width,mode.height,mode.fps);try{mediaRecorder.prepare();}catch(IOExceptione){Log.w(LOG_TAG,"failed to prepare MediaRecorder: "+e.getMessage());}}}privateMediaRecordercreateRecorder(intwidth,intheight,intfps){MediaRecorderrecorder;if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){recorder=newMediaRecorder(context);}else{recorder=newMediaRecorder();}recorder.setAudioSource(MediaRecorder.AudioSource.MIC);recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);recorder.setOutputFile(emptyVideoFile(context));recorder.setVideoEncodingBitRate(1_0_000_000);recorder.setVideoSize(width,height);recorder.setVideoFrameRate(fps);recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);recorder.setInputSurface(recorderSurface);recorder.setOnErrorListener(this);recorder.setOnErrorListener(this);returnrecorder;}