0

我正在尝试使用 phoneGap 录制示例音频,但没有成功。

根据文档,我所做的非常简单:

<script>
var media = null;

function record(){
   media = new Media("audio.wav");
   media.startRecord();
}
</script>

“audio.wav”存在于我的“www”文件夹中,是一个空的 wav 文件。每当此代码块运行时,我都会收到此控制台错误:

 - ERROR: Method 'create:withDict:' not defined in Plugin 'Media'

 - FAILED pluginJSON = {"className":"Media","methodName":"create","arguments":["INVALID","952d1fe0-5ec7-5e48-d68a-74cc979878b5","audio.wav"]}

即使有那个错误,录音应该还在继续。但是当我尝试播放录音时,我在调试器上观看媒体对象,我看到'_duration:-1'

当我尝试在实际的 iPhone 设备上调试应用程序时,会出现不同的错误。

4

2 回答 2

1

实际上,问题是即使我认为我正确地在您所描述的根目录上创建了文件,但我后来无法访问它,即使我得到了它的 URI(由于某种原因找不到文件,在同一个目录中的文件是在一秒钟前创建的!!!!)。所以我发现(不是简单的方法..)我必须通过"documents://". 因此,当我创建新媒体时,我会执行以下操作:

var mediaFile = new Media ("documents://"+audioFileName).

如果我做了“var mediaFile = new Media(fileURI_I_Just_Created)它会说该文件不存在!!!!(必须爱phoneGap!)

于 2012-05-28T07:26:42.003 回答
0

您需要在根目录中创建一个空白 wav 文件,而不是 www 文件夹。获取根目录 URI 的方法之一是使用toURI()方法。

这是 URI 的样子:

file:///data/some/com.stack.overflow/

以下是如何在根目录中创建空白 wav 文件的示例:

function onDeviceReady() {
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
  fileSystem.root.getFile("blank.wav", {create: true, exclusive: false}, gotFileEntry, fail);
}

笔记:

create: Used to indicate that the file or directory should be created, if it does not exist. (boolean)
exclusive: By itself, exclusive has no effect. Used with create, it causes the file or directory creation to fail if the target path

已经存在。(布尔值)

于 2012-05-27T05:26:59.393 回答