Sov*_*iut 5 flash audio mp3 actionscript-3
我在ActionScript 3中创建了一个基本的MP3播放器.我有一个基本的进度条,可以显示该歌曲的播放量.进度计算为在0和1之间归一化的十进制百分比,如下:
var progress:Number = channel.position / sound.length;
Run Code Online (Sandbox Code Playgroud)
问题是,如果音频仍在加载/缓冲声音.长度不正确.这会导致我的进度条跳过,甚至向后移动,直到声音完全加载并且sound.length不再变化.
确定仍在加载的声音对象的最终长度的最佳方法是什么?
至少有两种选择:
1:将进度条保留为0%,并且在声音完全加载之前不要移动它.那是:
sound.addEventListener(Event.COMPLETE, onSoundComplete);
private function onSoundComplete(event:Event):void {
// Calculate progress
}
Run Code Online (Sandbox Code Playgroud)
2:基于已加载文件百分比的近似百分比.像这样的东西:
private var _sound:Sound = /* Your logic here */;
private var _channel:SoundChannel = _sound.play();
_sound.addEventListener(ProgressEvent.PROGRESS, onSoundProgress);
private function onSoundProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded / event.bytesTotal;
var approxProgress:Number
= _channel.position / _sound.length * percentLoaded;
// Update your progress bar based on approxProgress
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6046 次 |
最近记录: |