【问题标题】:AS3 - How can I find the total time of an mp3 before is downloaded?AS3 - 我怎样才能找到下载前 mp3 的总时间?
【发布时间】:2010-11-25 15:10:04
【问题描述】:

在完全下载 mp3 之前,我怎样才能找到它的总时间?我有这个在 TimerEvent.TIMER 上调用的函数

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;
 }

问题是只有当 mp3 完全下载时,totalTime 才是正确的..

【问题讨论】:

    标签: flash audio mp3


    【解决方案1】:

    看看mp3infoutil 库。

    【讨论】:

      【解决方案2】:

      最简单的方法是估计 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 都这样做。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-31
        • 2023-02-05
        • 1970-01-01
        • 2021-02-26
        • 2020-09-06
        • 1970-01-01
        • 1970-01-01
        • 2016-02-13
        相关资源
        最近更新 更多