2013-04-07 58 views
0
onfinish功能後不玩

我可以播放音樂與SoundManager類2,當我按下按鈕但是加載下一個聲音,當我嘗試通過onfinish功能它沒有做到這一點的功能工作的功能工作中當音樂播放完成它不會加載下一個聲音,這意味着我怎麼能得到這個工作,請參見下面的代碼。聲音在Soundmanger2

function playSong(id) { 
//Stop the sound from playing 
soundManager.destroySound(mySound); 

//If we're under, just go to the end! 
if (id < 0) 
    id = songs.length - 1; 

//If we're over, choose what to do via the repeat flag 
if (id >= songs.length) 
     id = 0; 

//Save some variables 
playingSongId = id; 
playingSong = songs[playingSongId]; 
track = playingSong.artist_name + " " + "-" + " " + playingSong.track_name; 

//Create the sound and begin playing whenever! 
soundManager.createSound({ 
    id: mySound, 
    url: playingSong.track_url, 
    multiShotEvents: true, 
    autoPlay: true, 
    stream: true, 
    onplay: function() { 
     setPlayingInfo(track); 
     setPauseState(false); 
     setPlayTime(); 

    }, 
    onfinish: function() { 
     playNextSong(); 
     /*//We'll only continue if we're shuffling or repeating if we past the end... 
     if (shuffle == false && (playingSongId + 1 >= songs.length) && repeat == false) { 
      //No more songs... 
      setPlayingInfo(); 
      setPauseState(false); 
      setPlayTime(); 
      playingSong = null; 
      playingSongId = null; 
      return; 
     } 
     else { 
      playNextSong(); 
     }*/ 
    }, 

該函數作爲下一個聲音的標題出現在標題中,但歌曲從不播放。最後,當我點擊的同時加載聲音的第一聲音鏈接和播放標題,如果我點擊按鈕加載下一個聲音出現在標題不加載不過。請注意,我通過ajax加載這些聲音,因爲聲音位於遠程服務器上。

回答

0

From SoundManager2's Revision History

Flash播放器11.6.602.171,由Adobe於2013年2月26日發佈,推出了一個問題與SM2的默認的Flash 8(flashVersion:8)基於API的JS/Flash互動,其中從回調中調用的SM2方法(如onfinish())將不起作用。這主要是打破了依次播放聲音的方法,連續加載一系列聲音等等。 (有關更多信息,請參見discussion。)

請注意,這不會影響正在使用soundManager.setup({ flashVersion: 9})的情況;但是,SM2默認使用flashVersion: 8。具體來說,Flash啓動的事件(例如聲音整理)使Flash-> JS調用SM2 API,後者調用用戶指定的事件處理程序。如果用戶指定的SM2 onfinish()處理程序立即調用類似play()的SM2方法來進行JS - > Flash調用,則此調用會以靜默方式失敗或被阻止。其他使用類似回調模式的JS + Flash庫也可能受到影響,前提是其SWF是針對Flash 8 API構建的。

懷疑時序或遞歸/堆棧問題,發現將setTimeout(callback, 0)引入用戶指定的SM2回調(如onfinish())可恢復順序/播放列表功能。

Adob​​e在3/12/2013發佈的Flash Player 11.6.602.180顯示了相同的行爲。爲了避免額外的黑客入侵,SM2將此應用於所有基於Flash 8的API回調,而不管安裝了哪種Flash Player版本。由於這種變化,預計沒有迴歸。

或者,通過使用soundManager.setup({ flashVersion: 9 })可避免此問題,因爲基於Flash 9的API似乎沒有此問題。

+0

正是我應該把'oundManager.setup({flashVersion:9})'應該從創建功能分開? – 2013-04-08 15:18:29