mp3 playback stop echoing, as3
Hitting play more than once, causes an echo and I can't stop my mp3 player. What's the best practice for mp3 playback?
var mySound:Sound = new Sound();
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler);
var myChannel:SoundChannel = new SoundChannel();
function myPlayButtonHa开发者_高级运维ndler (e:MouseEvent):void {
myChannel = mySound.play();
}
stopButton.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
myChannel.stop();
}
Here are two buttons to control volume globally. Let me know if this doesn't work.
var mySound:Sound = new Sound();
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler);
var myChannel:SoundChannel = new SoundChannel();
function myPlayButtonHandler (e:MouseEvent):void {
myChannel = mySound.play();
}
stopButton.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
myChannel.stop();
}
/*-----------------------------------------------------------------*/
//global sound buttons, add instance of 'killswitch' and 'onswitch' to stage
killswitch.addEventListener(MouseEvent.CLICK, clipKillSwitch);
function clipKillSwitch(e:MouseEvent):void{
var transform1:SoundTransform=new SoundTransform();
transform1.volume=0;
flash.media.SoundMixer.soundTransform=transform1;
}
onswitch.addEventListener(MouseEvent.CLICK, clipOnSwitch);
function clipOnSwitch(e:MouseEvent):void{
var transform1_:SoundTransform=new SoundTransform();
transform1_.volume=1;
flash.media.SoundMixer.soundTransform=transform1_;
}
I would do several things.
- Once play is hit, record that state in a var. Then if they hit play again, don't do anything if you are already in the 'play' state.
Another option: 2. Change the playbutton to a pause button. Then perform the stop action if the button is hit, instead. If they then hit pause, then switch the button back to play.
精彩评论