如何在应用程序中预览捕获音频文件
how to preview the Capture Audio file in application
如何在应用程序中预览和播放截取的录音文件(audio file)。任何人请让示例代码或项目提供 link 或代码。
function captureAudio() {
// Launch device audio recorder
navigator.device.capture.captureAudio(captureSuccess, captureError);
}
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
name = mediaFile.name;
}
};
// capture error callback
var captureError = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
// start audio capture
navigator.device.capture.captureAudio(captureSuccess, captureError, {limit:2});
<a href="#" data-role="button" id="button0" onclick="captureAudio()">Button</a>
您可以按照这些问题中提供的说明播放您下载的 mp3 文件:
- Can't play audio in Android device
function captureAudio() {
navigator.device.capture.captureAudio(captureSuccess, captureError);
}
function playMP3() {
media.play();
}
function captureError(e) {
console.log("capture error: "+JSON.stringify(e));
}
function captureSuccess(s) {
console.log("Success");
var a="<audio controls>"
a += "<source src='" + s[0].fullPath + "' type='video/mp4'>";
a += "</audio>";
document.querySelector("#audioArea").innerHTML = a;
}
<div data-role="page" id="page">
<div data-role="content" style="padding: 15px">
<a href="#" data-role="button" onclick="captureAudio()">audio</a>
<div id="audioArea" onclick="playMP3()"></div>
</div>
</div>
如何在应用程序中预览和播放截取的录音文件(audio file)。任何人请让示例代码或项目提供 link 或代码。
function captureAudio() {
// Launch device audio recorder
navigator.device.capture.captureAudio(captureSuccess, captureError);
}
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
name = mediaFile.name;
}
};
// capture error callback
var captureError = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
// start audio capture
navigator.device.capture.captureAudio(captureSuccess, captureError, {limit:2});
<a href="#" data-role="button" id="button0" onclick="captureAudio()">Button</a>
您可以按照这些问题中提供的说明播放您下载的 mp3 文件:
- Can't play audio in Android device
function captureAudio() {
navigator.device.capture.captureAudio(captureSuccess, captureError);
}
function playMP3() {
media.play();
}
function captureError(e) {
console.log("capture error: "+JSON.stringify(e));
}
function captureSuccess(s) {
console.log("Success");
var a="<audio controls>"
a += "<source src='" + s[0].fullPath + "' type='video/mp4'>";
a += "</audio>";
document.querySelector("#audioArea").innerHTML = a;
}
<div data-role="page" id="page">
<div data-role="content" style="padding: 15px">
<a href="#" data-role="button" onclick="captureAudio()">audio</a>
<div id="audioArea" onclick="playMP3()"></div>
</div>
</div>