AudioPlayer Error: stopPlaying() called during invalid state: 0
when I try to play a sound with Phonegap i get th开发者_运维技巧e following error:
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)
here is my play function:
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()
}
any ideas?
One thing you probably want to do is make sure you're trying to stop something that is actually currently playing. Something like this:
if (lastMedia != null && lastMedia.isPlaying()){
    lastMedia.stop()
    lastMedia.release()
}
// init Media like this
`
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;
        }});
`
// last callback to be called when media status has changed.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论