PhoneGapでオーディオメディアレコーダー/プレーヤーを構築しています。それはすべて美しく働いていますが、私は鉄に見えないようなしわを打ちました。PhoneGapはMedia APIからgetDuration()を呼び出せませんが、他のメソッドは動作します
my_media.play();
実際には、私のEclipseまたはXCodeコンソールでメディアのw/oエラーが再生されるため、-1が表示されているアラートが困惑しています。 my_media.getDuration();
は、再生しようとしているファイルの再生時間を返すと思います。
私のtry/catchブロックはエラーを投げているわけではありません。私はこの1つに非常に困惑しています。 Here's the PhoneGap documentation on Media.getDuration()。
function playAudio() {
$('#btnStopRecording').removeClass('ui-disabled');
$('#btnPlayMessage, #btnStartStopRecording, #btnDeleteMessage, #btnAcceptUpload').addClass('ui-disabled');
my_media = new Media(fullRecordPath,
// success callback
function() {
$('#btnPlayMessage, #btnStartStopRecording, #btnDeleteMessage, #btnAcceptUpload').removeClass('ui-disabled');
$('#btnStopRecording').addClass('ui-disabled');
},
// error callback
function (err) {
console.log("attempting to play fullRecordPath = "+fullRecordPath);
console.log("playAudio():Audio Error: " + err.code);
}
);
var thisDuration;
try{
thisDuration = my_media.getDuration();
} catch (err) {
console.log("attempting to get duration error code "+err.code);
console.log("attempting to get duration error message "+err.message);
}
alert("we're about play a file of this duration "+thisDuration);
my_media.play();
// stop playback when the stop button is tapped
$('#btnStopRecording').off('tap').on('tap',function()
{
my_media.stop();
$('#btnPlayMessage, #btnStartStopRecording, #btnDeleteMessage, #btnAcceptUpload').removeClass('ui-disabled');
$('#btnStopRecording').addClass('ui-disabled');
});
// if the user leaves the page, stop playback
$('#pageRecordMessage').live('pagehide', function()
{
my_media.stop();
$('#btnPlayMessage, #btnStartStopRecording, #btnDeleteMessage, #btnAcceptUpload').removeClass('ui-disabled');
$('#btnStopRecording').addClass('ui-disabled');
});
}
私はsetIntervalにあなたが好きですが、それでも動作しません。常に-1を返します。理由は何でしょうか?それはうまく実行されているためです。ファイルタイプが問題になる可能性がありますか?私はmp3を使用しています –