How do I know that a playback audio has reached the end?

0

So I would like to know when my audio has reached the end of the playback, follow my code to start the audio and stop, thank you right away!

private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

try {
    mRecorder.prepare();
} catch (IOException e) {
    Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();}

private void stopRecording() {
mRecorder.stop();
mRecorder.release();
mRecorder = null;

uploadAudio();

}

    
asked by anonymous 22.07.2017 / 21:03

1 answer

0

Dude, the FileObserver class caters to this question, follow the Documentation , very simple to use, and when the file is closed (ends the recording), callback onEvent is called with the CLOSE_WRITE parameter.

Follow the example:

MyFileObserver fb = new MyFileObserver(mediaFile_path, FileObserver.CLOSE_WRITE);
fb.startWatching();

class MyFileObserver extends FileObserver {

    public MyFileObserver (String path, int mask) {
        super(path, mask);
    }

    public void onEvent(int event, String path) {
        //uploadAudio();
    }
}

Do not forget to call the stopWatching() method ... Original answer )

    
27.07.2017 / 20:08