当我尝试使用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 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()
}
任何想法?
答案 0 :(得分:3)
你可能想要做的一件事是确保你试图阻止实际上正在播放的东西。像这样:
if (lastMedia != null && lastMedia.isPlaying()){
lastMedia.stop()
lastMedia.release()
}
答案 1 :(得分:0)
// init这样的媒体
`
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;
}});
`
//媒体状态发生变化时要调用的最后一个回调。