In android, how to show the preview surface before starting recording a media recorder. my application has a video recording function, when I go to the video clip, it displays a black screen when I start recording using the start button. A camera preview is the display and start of recording.
How to start a preview before recording. I added the code that I used in the onCreateView () fragment -
surfaceHolder = mySurfaceView.getHolder(); camera = Camera.open(); if(camera!=null){ camera.setDisplayOrientation(90); Camera.Parameters param; param = camera.getParameters(); param.setPreviewFrameRate(20); param.setPreviewSize(176, 144); camera.setParameters(param); camera.setPreviewDisplay(surfaceHolder); } mediaRecorder = new MediaRecorder(); camera.unlock(); mediaRecorder.setCamera(camera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); CamcorderProfile camcorderProfile_HQ = CamcorderProfile .get(CamcorderProfile.QUALITY_HIGH); mediaRecorder.setProfile(camcorderProfile_HQ); String filePath = getOutputMediaFile(MEDIA_TYPE_VIDEO).getPath(); fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); mediaRecorder.setOutputFile(filePath);
and the code that I used when I clicked the start button is
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface()); mediaRecorder.prepare(); mediaRecorder.start();
therefore, I can transcode the video using the code above, but I could not show the preview before starting recording. Please help me where I am absent. To do this, a black screen is displayed before transcoding the video.
Thanks in advance.
source share