1

I have this code to stream a mp3 file:

var isPlaying:Boolean;
var pausePoint:Number;

var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound( new URLRequest( 'mp3file.mp3' ) );
var volumeAdjust:SoundTransform = new SoundTransform();

soundChannel = sound.play();
isPlaying = true;

function clickPlayPause(evt:MouseEvent) {

    if (isPlaying) 
    {
       pausePoint = soundChannel.position;
       soundChannel.stop();
       //hide pause sign
       control_mc.play_btn.pausee.alpha = 0;
       //show play sign
       control_mc.play_btn.playy.alpha = 1;
       isPlaying = false;

    } else {

        soundChannel = sound.play(pausePoint);
        isPlaying = true;
       //hide play sign
       control_mc.play_btn.playy.alpha = 0;
       //show pause sign
       control_mc.play_btn.pausee.alpha = 1;

    }
}

function clickStop(evt:MouseEvent) {
    if (isPlaying) {
        soundChannel.stop();
        isPlaying = false;
    }
    pausePoint = 0.00;
}

So as you can see, the code above also includes some event handling functions to handle my play/pause button. It all works, but it takes a good two seconds for the music to actually stop playing. It also takes a while to start back up again. Does anyone know why this is? And how I can fix it?

Thanks

Benny
  • 2,250
  • 4
  • 26
  • 39
  • 1
    The above code should not be responsible for the lag. Check out other parts of your program... – loxxy Oct 05 '12 at 09:55
  • That's all the code I have. There is nothing else it could be. It was also doing this before I even had a play/pause button. Just tried with a different MP3 file as well - still occurring. –  Oct 05 '12 at 10:26

1 Answers1

0

Greensock tweener has the features to fade in and fade out the audio, that will help you to hide the lag while hearing the audio file.

Import the Greensock tweener and activate the plugins

import com.greensock.*;
import com.greensock.plugins.*;


TweenPlugin.activate([VolumePlugin]);

then

if(palying){
   TweenLite.to(soundChannel, .5, {volume:0});
}else{
   TweenLite.to(soundChannel, .5, {volume:1});
}
Benny
  • 2,250
  • 4
  • 26
  • 39