2010-11-25 26 views
0

如何在完全下載之前找到mp3的總時間?我有這個功能,這就是所謂的TimerEvent.TIMERAS3 - 如何在下載之前找到mp3的總時間?

private function onTick(e:TimerEvent):void 
{ 
    _soundLength = _sound.length; 
    _position = _channel.position; 
    mp3Interface.timeBar.timers.elapsedTime.text = ascb.util.DateFormat.formatMilliseconds(_position); 
    mp3Interface.timeBar.timers.totalTime.text = ascb.util.DateFormat.formatMilliseconds(_soundLength); 
    var percentPlayed:Number = Math.round((_position/_soundLength)*100); 
    mp3Interface.timeBar.seeker.x = (percentPlayed*mp3Interface.timeBar.progressBar.width-5)/100; 
} 

的問題是THA的TOTALTIME是正確的,只有當MP3完全下載..

回答

1

做到這一點,最簡單的方法是估計的MP3文件的長度,基於總文件大小和到目前爲止加載的字節:

//the loading progress handler 
private function progressHandler(e:ProgressEvent){ 
    _soundLength = _sound.length*e.bytesTotal/e.bytesLoaded; 
} 

它給出了一個相當不錯的估計。 _soundLength屬性可能會變化1或2秒,直到加載完成。無論如何,這是找出任何mp3長度的唯一方法。當然,如果你的mp3文件有ID3信息,你可以從那裏得到MP3的長度,但並不是所有的MP3都可以。

相關問題