5

I am developing an audio recording application using MediaRecorder class. I have the following requirement:

1.When a pause button is pressed then pause recording.

2.When a resume button is pressed then resume recording where it paused. I try this link

But I am unable to implement the functionality.

Any help/suggestion would be greatly appreciated.

Community
  • 1
  • 1
Rana
  • 134
  • 2
  • 2
  • 11

4 Answers4

4

This link also may useful for those who need to pause and record audio.

https://github.com/lassana/continuous-audiorecorder

selva_pollachi
  • 4,147
  • 4
  • 29
  • 42
  • don't use this unmaintained shi**y library. app will be crashed on many devices with no fix https://github.com/lassana/continuous-audiorecorder/issues/24 The author also didn't response on these issues. – Qadir Hussain Oct 13 '21 at 08:02
2

Media Recorder class does not support to pause and resume , see second link class overview try to use stop and restart

How can i pause voice recording in Android?

http://developer.android.com/reference/android/media/MediaRecorder.html

http://www.techotopia.com/index.php/Android_Audio_Recording_and_Playback_using_MediaPlayer_and_MediaRecorder

Community
  • 1
  • 1
Nikhil Desale
  • 76
  • 1
  • 7
1

You can refer my answer here if still have this issue.

The solution is to stop recorder when user pause and start again on resume as already mentioned in many other answers in stackoverflow. Store all the audio/video files generated in an array and use below method to merge all media files. The example is taken from mp4parser library and modified little bit as per my need.

public static boolean mergeMediaFiles(boolean isAudio, String sourceFiles[], String targetFile) {
        try {
            String mediaKey = isAudio ? "soun" : "vide";
            List<Movie> listMovies = new ArrayList<>();
            for (String filename : sourceFiles) {
                listMovies.add(MovieCreator.build(filename));
            }
            List<Track> listTracks = new LinkedList<>();
            for (Movie movie : listMovies) {
                for (Track track : movie.getTracks()) {
                    if (track.getHandler().equals(mediaKey)) {
                        listTracks.add(track);
                    }
                }
            }
            Movie outputMovie = new Movie();
            if (!listTracks.isEmpty()) {
                outputMovie.addTrack(new AppendTrack(listTracks.toArray(new Track[listTracks.size()])));
            }
            Container container = new DefaultMp4Builder().build(outputMovie);
            FileChannel fileChannel = new RandomAccessFile(String.format(targetFile), "rw").getChannel();
            container.writeContainer(fileChannel);
            fileChannel.close();
            return true;
        }
        catch (IOException e) {
            Log.e(LOG_TAG, "Error merging media files. exception: "+e.getMessage());
            return false;
        }
    }

Use flag isAudio as true for Audio files and false for Video files.

Community
  • 1
  • 1
Nitin Mathur
  • 551
  • 5
  • 19
0
for pause the mediarecorder
         my_rec.pause();
         im_pouse.setImageResource(R.drawable.ic_play_arrow_black_24dp);

    for resume the mediarecorder
         my_rec.resume();
         im_pouse.setImageResource(R.drawable.ic_pause_black_24dp);

Hope it works.

Jaimil Patel
  • 1,301
  • 6
  • 13
  • Welcome to Stack Overflow! While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – rizerphe Jun 16 '20 at 11:03