0
我有一個播放,暫停和下一個按鈕在一個幀上的閃存MP3播放器。
歌曲存儲在一個數組中。
一切正常,除了 暫停按鈕。它暫停音樂
並將歌曲位置保存在變量中。 當我再次點擊暫停
按鈕時,歌曲應該從已保存的歌曲位置
播放 。問題在於它也是 播放數組中的第一首歌曲。不是
已暫停的歌曲。我試過 在Google上尋找解決方案。但
我可以找到哪些關於只播放一首歌曲的MP3播放器的主題。
這是代碼。謝謝。AS3暫停按鈕不播放陣列中暫停的歌曲
var i:Number = 0;
var myMusic:Sound = new Sound();
var mySongs:Array = ["Kalimba.mp3","Sleep Away.mp3","Maid with the Flaxen Hair.mp3"];
var soundFile:URLRequest = new URLRequest(mySongs[i++]);
var channel:SoundChannel = new SoundChannel();
var sTransform:SoundTransform = new SoundTransform();
var songPosition:Number;
var myContext:SoundLoaderContext = new SoundLoaderContext(5000);
myMusic.load(soundFile, myContext);
btnPlay.addEventListener(MouseEvent.CLICK, playMusic);
btnNext.addEventListener(MouseEvent.CLICK, nextMusic);
btnPause.addEventListener(MouseEvent.CLICK, pauseMusic);
channel.addEventListener(Event.SOUND_COMPLETE, nextMusic);
function playMusic(evt:MouseEvent):void
{
channel = myMusic.play(songPosition);
channel.addEventListener(Event.SOUND_COMPLETE, nextMusic);
}
function nextMusic(evt:Event):void
{
channel.stop();
var myMusic:Sound = new Sound();
var mySongs:Array = ["Kalimba.mp3","Sleep Away.mp3","Maid with the Flaxen Hair.mp3"];
var soundFile:URLRequest = new URLRequest(mySongs[i]);
myMusic.load(soundFile, myContext);
channel = myMusic.play(i);
channel.addEventListener(Event.SOUND_COMPLETE, nextMusic);
if(i==mySongs.length-1) {
i=0;
}
else {
i++;
}
}
var Paused:Boolean = false;
function pauseMusic(evt:MouseEvent):void
{
if(Paused==false) {
songPosition = channel.position;
channel.stop();
Paused = true;
}
else if(Paused==true) {
channel = myMusic.play(songPosition);
Paused = false;
}
}
我刪除了channel.addEventListener(Event.SOUND_COMPLETE,nextMusic); – Nax
不幸的是,它並沒有解決暫停問題。 – Nax
爲了確保我刪除了所有的channel.addEventListener(Event.SOUND_COMPLETE,nextMusic);但仍然沒有。 – Nax