Player BAM5 told me about code his friend Shango wrote, for

extrapolating the total duration of an mp3 while it was loading.
Sure enough: we have length (so far), bytesLoaded and bytesTotal.
So: do that. It works pretty well!

Too bad we can't do something similar for FLVs that don't have metadata.
:( (there is no "current length" property, just a current position.
So any time estimate would get worse and worse as the bytes advanced
past the play position.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@719 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2008-11-19 05:19:38 +00:00
parent be24ecee84
commit 8584678701
@@ -77,7 +77,12 @@ public class Mp3AudioPlayer extends EventDispatcher
if (_sound == null) {
return NaN;
}
return _sound.length / 1000;
const duration :Number = _sound.length / 1000;
if (_isComplete) {
return duration;
}
// extrapolate the total duration based on the current length and current bytesLoaded
return (duration / _sound.bytesLoaded) * _sound.bytesTotal;
}
// from AudioPlayer
@@ -233,8 +238,8 @@ public class Mp3AudioPlayer extends EventDispatcher
*/
protected function handleLoadingComplete (event :Event) :void
{
handlePositionCheck(); // also updates duration
_isComplete = true;
dispatchEvent(new ValueEvent(MediaPlayerCodes.DURATION, getDuration()));
}
protected function handlePlaybackComplete (event :Event) :void