How to use onPause and onResume methods with Media Recorder on Android?

236
January 14, 2018, at 1:08 PM

I am trying to make a custom video recording app in android. But I could not get pause and resume functionality to work on Android 7 and above. The code being used is here: link. The code has been provided by google.

What I am trying to do :

  • Step 1: Start recording.
  • Step 2: Record for 10 seconds
  • Step 3: Click on pause (mediaRecorder.pause())
  • Step 4: Wait for 5 sec
  • Step 5: Clik on resume (mediaRecorder.resume())
  • Step 6: Record for another 10 seconds and stop.

What is expected:

A video of 20 seconds with first half including the video recorded in Step 1 to Step 2 and the second half starting from Step 5 to Step 6.

What I am getting?

A final video of 25 seconds. The first 10 seconds have the first part of the video. Then a still image (last frame of the first half) stays for another 5 seconds. Then the second half of 10 seconds. Also, the audio starts and runs for the first 10 seconds then the audio should pause but instead the audio from second part of the video starts playing at the 11th second to 20th second. The video from the second part starts at 15th sec and ends at 25.

Is this a bug with Android or is there any technique I could use to fix this.

I am using mp4 parser to join videos below Android 7 but I want to use androids onPause and onResume methods for Android 7 and above.

This is what I am doing on pressing the Pause Video button:

if(isVideoPaused){
                    mMediaRecorder.resume();
                    isVideoPaused=false;
                }
                else {
                    mMediaRecorder.pause();
                    isVideoPaused=true;
                }

Any help would be greatly appreciated. Thanks!

READ ALSO
Change spinner's default value

Change spinner's default value

I have a spinner with a list of all the countriesEssentially, I need a piece of code that gets me the position of not the selected item, but rather a certain one I specify

145
Why doesn't Google Fit distance match fit app?

Why doesn't Google Fit distance match fit app?

The google fit faq states that in order to match the distance and step values of the official google fit app, we should be using the following data request

176
Handling out of memory in a Native Android App

Handling out of memory in a Native Android App

I have a C++ Android app that periodically crashes on devices with only 768MB RAM because it runs out of memoryThe application crashes in "malloc" or "dlmalloc_real" on these devices

222
Json.Net JToken does not serialize all properties on Xamarin.Forms Android

Json.Net JToken does not serialize all properties on Xamarin.Forms Android

I have a cross-platform XamarinForms app that uses Json

227