我正在尝试提取MediaRecorder
的muxer部分,所以我现在正在学习Android 4.2.2的源代码,反正那不重要。
我在这里有一个问题。这是关于 MediaRecorder.java
的 setOutputFile(String path)
。
MediaRecorder.java
的调用结果为
MediaRecorder.java
+- android_media_MediaRecorder.cpp
+- MediaRecorder.cpp
+- MediaPlayerService.cpp
+- MediaRecorderClient.cpp
+- StagefrightRecorder.cpp
但是在 StagefrightRecorder.cpp
中,它说
status_t StagefrightRecorder::setOutputFile(const char *path) {
ALOGE("setOutputFile(const char*) must not be called");
// We don't actually support this at all, as the media_server process
// no longer has permissions to create files.
return -EPERM;
}
那如何继续使用MediaRecorder
的setOutputFile(String path)
呢?我真的不明白。
最佳答案
在 MediaRecorder.java
中,setOutputFile
是在 Java
层本身处理的,没有相应的 native 实现。在 Java
实现中,path is stored into mPath
.
当 prepare
被调用时,a FileOutputStream
is created and passed to the native implementation of setOutputFile
从这个实现中可以看出,它接受了一个 File Descriptor
。 native 实现支持此方法,即采用 File Descriptor
,因此生成输出并将其存储到文件系统中。
因此,在 MediaRecorderTest.java
等示例中,可以观察到 MediaRecorder
对象是使用 string
作为输出文件路径初始化的.
关于android - [Android]为什么我们仍然可以使用MediaRecorder的setOutputFile(String path)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23531123/