The media plug-in uses the following methods to determine the overall time.
media.getDuration()
References
http://docs.monaca.mobi/cur/ja/reference/phonegap_34/ja/media/
It also says user7461, but
During a performance, the current position (time) can be obtained in media.getCurrentPosition().
The overall length (performance time for the entire track) can be obtained by media.getDuration().
However, as far as I checked on Android environment, even if I called getDuration() immediately after new Media(), -1 was returned, and when I ran play() in getCurrentPosition() callback, the correct value was returned (I don't know if it's just my environment or specification).
If I were to display what percentage, would it be like this?
verticalTime = null; varmedia = new Media(url, onSuccess, onError); // If I say media.getDuration() here, does it return -1? media.play(); setInterval(function(){ media.getCurrentPosition(function(position){ if(totalTime==null) { totalTime=media.getDuration(); } varelapped=(100*position/totalTime).toFixed(1)+"%"; document.getElementById('elapsed').innerHTML =elapsed; }, function(e){ console.log("Error getting pos="+e); document.getElementById('elapped').innerHTML="Error:"+e; }); }, 1000);
© 2024 OneMinuteCode. All rights reserved.