更新时间:2023-11-20 23:49:22
在 FileObserver
类适合您的需求完美。 这里是文档。它易于使用。当观察到的文件写入后关闭时,的onEvent
回调调用 CLOSE_WRITE
作为参数。
The FileObserver
class suits your needs perfectly. Here is the documentation. Its 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
}
}
不要忘记调用 stopWatching()
..