views:

435

answers:

1

Hi, i have a player in flash action 3. i need to take a the total time of the sound file and current time of the sound file. how can i code like this.

function onPlayProgress(evt:Event):void {
      var sndLength:int = Math.ceil(snd.length /(snd.bytesLoaded / snd.bytesTotal));
      var seekbar = 100 * (channel.position / sndLength);
      playBar.seekbar.x = seekbar*5.8;
      var _totalTime:Number = (((snd.length /(snd.bytesLoaded / snd.bytesTotal))*0.001/60));

what is current time??????????

A: 

I'm not entirely clear on what the code sample you provided is trying to communicate, but if you want to get the current position of a sound that's playing you would do something like this:

protected var sound:Sound; 
protected var soundChannel:SoundChannel;

protected function loadSound():void
{
    sound = new Sound(new URLRequest("path_to_sound.mp3"));
    sound.addEventListener(Event.COMPLETE, onSoundLoadComplete);
{

protected function onSoundLoadComplete(e:Event):void
{
    sound.removeEventListener(Event.COMPLETE, onSoundLoadComplete);
    soundChannel = sound.play();
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

protected function onEnterFrame(e:Event):void
{
   var minutes:uint = Math.floor(soundChannel.position / 1000 / 60);
   var seconds:uint = Math.floor(soundChannel.position / 1000) % 60;
   trace('position: ' + minutes + ':' + seconds);


}
heavilyinvolved
ok i got , but how can i convert this in minute :(
coderex
Thank you verymuch
coderex
how do u get total time?
coderex
sound.length returns the length of the sound in milliseconds. Convert that value in the same way the current position is being converted. It's a little confusing b/c on one hand you have to use the Sound object and on the other you have to use the SoundChannel object. Check Adobe's documentation... it's quite complete.
heavilyinvolved
hmm the conversion and the channel position are very diffrent :). i think i need to check the API doc for this... :( . . .
coderex