AudioPlayer错误:无效状态期间调用stopPlaying:0

问题描述

|| 当我尝试使用Phonegap播放声音时,出现以下错误
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 @R_502[email protected](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()
}
有任何想法吗?     

解决方法

        您可能想做的一件事就是确保您正在尝试停止当前正在播放的内容。像这样:
if (lastMedia != null && lastMedia.isPlaying()){
    lastMedia.stop()
    lastMedia.release()
}
    ,        //这样的初始化媒体 `
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;
        }});
` //媒体状态更改时要调用的最后一个回调。