如何在应用程序中预览Capture Audio文件

时间:2016-04-18 08:17:11

标签: cordova voice

如何在应用程序中预览和播放捕获的录音文件(音频文件)。任何人请提供示例代码或项目提供的链接或代码。



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});
&#13;
<a href="#" data-role="button" id="button0" onclick="captureAudio()">Button</a>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您可以按照以下问题中提供的说明播放已下载的mp3文件:

答案 1 :(得分:0)

&#13;
&#13;
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;
}
&#13;
<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>
&#13;
&#13;
&#13;