2011-05-29 46 views
1

,當我嘗試播放與PhoneGap的聲音,我得到以下錯誤:AudioPlayer錯誤:stopPlaying()無效狀態時稱爲:0

05-29 16:26:14.225 1749 2777 I System.out: AudioPlayer Error: stopPlaying() called during invalid state: 0 
05-29 16:26:14.257 1749 2778 W System.err: java.io.FileNotFoundException: www/sounds/863.ogg 
05-29 16:26:14.257 1749 2778 W System.err: at android.content.res.AssetManager.openAssetFd(Native Method) 
05-29 16:26:14.257 1749 2778 W System.err: at android.content.res.AssetManager.openFd(AssetManager.java:331) 
05-29 16:26:14.257 1749 2778 W System.err: at com.phonegap.AudioPlayer.startPlaying(AudioPlayer.java:201) 
05-29 16:26:14.257 1749 2778 W System.err: at com.phonegap.AudioHandler.startPlayingAudio(AudioHandler.java:181) 
05-29 16:26:14.257 1749 2778 W System.err: at com.phonegap.AudioHandler.execute(AudioHandler.java:64) 
05-29 16:26:14.257 1749 2778 W System.err: at com.phonegap.api.PluginManager$1.run(PluginManager.java:86) 
05-29 16:26:14.257 1749 2778 W System.err: at java.lang.Thread.run(Thread.java:1096) 

這裏是我的播放功能:

lastMedia = null 
function play(id){ 
    alert('playing ' + id) 
    if (lastMedia){ 
     lastMedia.stop() 
     lastMedia.release() 
    } 
    lastMedia = new Media('/android_asset/www/sounds/'+id+'.ogg', function(){}/*, function(err){alert('error: ' + err)}*/) 
    lastMedia.play() 
} 

有任何想法嗎?

回答

3

您可能想要做的一件事是確保您試圖阻止實際上正在播放的內容。事情是這樣的:

if (lastMedia != null && lastMedia.isPlaying()){ 
    lastMedia.stop() 
    lastMedia.release() 
} 
+0

謝謝。我發現錯誤:我他找不到聲音... – nomoral 2011-05-29 15:18:08

+0

@nomoral請標記此線程爲他人解決。 – 2011-05-29 16:15:08

+0

媒體類不提供「isPlaying」方法。 – 2013-06-14 09:44:30

0

//初始化媒體這樣
`

lastMedia = 
    new Media('/android_asset/www/sounds/'+id+'.ogg', 
      function(){}, 
      function(err){alert('error: ' + err)}, 
      function(statusCode){ 
      switch(statusCode){ 
      case Media.MEDIA_PAUSED: 
      case Media.MEDIA_STOPPED: 
       lastMedia = null; 
       break; 
      default: 
       break; 
     }}); 

`

//最後回調時媒體的地位已經改變了被調用。

相關問題