Android MediaRecorder Video - Audio and Video track playing subsequently

LippelLippel DEMember ✭✭

I came a across a bug, mostly present on samsung devices. I record a video with media recorder (code shown below). It worked flawlessly, on all devices, but now on some Android Devices the Audio and Video track are separated.

Say I'm capturing 5 sec of Video. The Video will be 5 sec long, playing the video will play the first frame of the video and the 5 secs of Audio. After that, the 5 secs of Video are being played. The default video player shows that the video is over after 5 sec, but in fact its only the audio...

Is there anything newly introduced to 8.0 Oreo, so that I have to adapt my MediaRecorder?

My media recorder setup:

private void SetUpMediaRecorder()
        {
            MediaRecorder.SetAudioSource(AudioSource.Mic);
            MediaRecorder.SetVideoSource(VideoSource.Surface);
            MediaRecorder.SetOutputFormat(OutputFormat.Mpeg4);

            MediaRecorder.SetVideoEncoder(VideoEncoder.H264);
            MediaRecorder.SetAudioEncoder(AudioEncoder.Aac);
            MediaRecorder.SetOutputFile(outputURL);
            MediaRecorder.SetVideoSize(1280, 720);

            MediaRecorder.SetVideoFrameRate(30);
            MediaRecorder.SetVideoEncodingBitRate(2000000);
            MediaRecorder.SetMaxDuration(VideoManager.MAX_VIDEODURATION_MS);

            //Set audio bitrate
            int bitDepth = 16;
            int sampleRate = 44100;
            int bitRate = sampleRate * bitDepth;
            MediaRecorder.SetAudioEncodingBitRate(bitRate);
            MediaRecorder.SetAudioSamplingRate(sampleRate);

            int rotation = (int)ThisActivity.WindowManager.DefaultDisplay.Rotation;
            int orientation = orientations[rotation];
            MediaRecorder.SetOrientationHint(orientation);
            MediaRecorder.Prepare();
        }
Sign In or Register to comment.