Sto costruendo un registratore/lettore multimediale audio con PhoneGap. Funziona tutto magnificamente, ma ho colpito una ruga che non riesco a stirare.PhoneGap non riesce a getDuration() dall'API multimediale, ma altri metodi funzionano
my_media.play();
riproduce effettivamente il supporto senza errori nelle mie console Eclipse o XCode, motivo per cui l'avviso che mostra un -1 è sconcertante. Mi aspetto my_media.getDuration();
per restituire la durata del file che sto tentando di riprodurre.
Il mio blocco try/catch non sta generando un errore, sono piuttosto perplesso su questo. 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');
});
}
Mi piace come setInterval ma non funziona ancora. Ritorna sempre -1. Quale può essere il motivo? Perché sta funzionando bene. Il tipo di file può essere il problema? Sto usando mp3 –