1
我正在編寫一個應用程序,它將接收音頻文件,然後將其上傳到Teleriks永久服務。我想阻止用戶上傳長度超過20秒的任何音頻文件。Cordova Media Capture - 查找音頻文件的持續時間
但經過測試,似乎無論音頻文件的持續時間,「data.duration」似乎總是返回0,所以無論文件上傳了什麼。
這是我使用的插件:https://github.com/apache/cordova-plugin-media-capture
這是我的代碼:
var el = new Everlive('app-id-here'); //Taken away ID for stackoverflow
var options = {
fileName: 'testaudio.mp3',
mimeType: 'audio/mpeg3'
};
function formatSuccess(data) {
if (data.duration > 20) {
alert("The audio file you have used is longer than 20 seconds.");
} else {
alert(data.duration);
el.files.upload(capturedFiles[0].fullPath, options)
.then(function() {
alert('success');
}, function (err) {
alert(JSON.stringify(err));
});
}
}
function formatFail() {
alert("Error accessing file data");
}
capturedFiles[0].getFormatData(formatSuccess, formatFail);
你有沒有找到這方面的解決方案?我也得到-1持續時間。 – Mikethetechy