【问题标题】:[Android]Why can we still use setOutputFile(String path) of MediaRecorder?[Android]为什么我们还可以使用MediaRecorder的setOutputFile(String path)?
【发布时间】:2014-06-25 05:12:15
【问题描述】:

我正在尝试提取MediaRecorder的muxer部分,所以我现在正在学习Android 4.2.2的源代码,反正这并不重要。 我在这里有一个问题。关于setOutputFile(String path)MediaRecorder.java

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;
}

那我们怎样才能继续使用MediaRecordersetOutputFile(String path)呢?我真的不明白。

【问题讨论】:

    标签: android android-source android-mediarecorder stagefright


    【解决方案1】:

    MediaRecorder.java 中,setOutputFileJava 层本身处理,没有相应的本机实现。在Java 实现中,path is stored into mPath

    prepare 被调用时,a FileOutputStream is created and passed to the native implementation of setOutputFile 接受File Descriptor,从这个实现中可以看出。本机实现支持这种方法,即接收File Descriptor,因此生成输出并将其存储到文件系统中。

    因此,在MediaRecorderTest.java 等示例中,可以观察到MediaRecorder 对象被初始化为string 作为输出文件路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-04
      • 2020-08-04
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 2021-01-14
      相关资源
      最近更新 更多