How to know when MediaRecorder has finished writing data to file

前端 未结 6 964
迷失自我
迷失自我 2021-02-05 08:01

We\'re using MediaRecorder to record video to a file on the external storage using setOutputFile() before doing the actual recording.

Everything works fine, but the main

6条回答
  •  再見小時候
    2021-02-05 08:26

    The FileObserver class suits your needs perfectly. Here is the documentation. It's easy to use. When a observed file is closed after writing, the onEvent callback is called with CLOSE_WRITE as the parameter.

    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) {
            // start playing
        }
    }
    

    Don't forget to call stopWatching().

提交回复
热议问题