gpt4 book ai didi

cordova - 使用Cordova从智能手机录制音频

转载 作者:行者123 更新时间:2023-12-03 00:14:57 25 4
gpt4 key购买 nike

我是Cordova的非常新的,并且我正在尝试创建一个非常基本的应用来录制来自智能手机的音频。
因此,我使用VS 2015添加了cordova-plugin-media-capture插件。
然后,我从doc复制/粘贴this full example:

<head>
<title>Capture Audio</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
//I just remove the following line in MY code, I don't know what it corresponds
<script type="text/javascript" charset="utf-8" src="json2.js"></script>

<script type="text/javascript" charset="utf-8">
// Called when capture operation is finished
function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}

// Called if something bad happens.
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
function captureAudio() {
// Launch device audio recording application,
// allowing user to capture up to 2 audio clips
navigator.device.capture.captureAudio(captureSuccess, captureError, {limit: 2});
}

// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;

ft.upload(path,
"http://my.domain.com/upload.php",
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
{ fileName: name });
}
</script>
</head>
<body>
<button onclick="captureAudio();">Capture Audio</button> <br>
</body>
但是,当我运行此代码并单击“捕获音频”按钮时,我得到以下结果:
capture.captureAudio fail
我也在控制台中出现以下错误:

missing exec:Capture.captureAudio

TypeError: emulator[service][action] is not a function
at module.exports.exec (ripple.js:41)
at _capture (capture.js:52)
at Capture.captureAudio (capture.js:71)
at captureAudio (index.html:60)
at HTMLButtonElement.onclick (index.html:91)


我真的不明白问题出在哪里...
谢谢 !

最佳答案

您正在尝试使用波纹仿真器测试您的应用程序,该仿真器只是一个仿真器,并不模拟所有设备功能,例如录制音频文件。另请参见this answer

尝试使用真实的设备来测试您的应用。

编辑:我不确定是否有任何仿真器实际上可以通过您的PC硬件捕获声音。例如,Android模拟器不能。

The Android Emulator does not have the ability to capture audio, but actual devices are likely to provide these capabilities.



取自 adroid.developer.com MediaRecorder documentation

关于cordova - 使用Cordova从智能手机录制音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35845052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com