[英]AudioPlayer Error: stopPlaying() called during invalid state: 0
when I try to play a sound with Phonegap i get the following error:当我尝试使用 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)
here is my play function:这是我的游戏 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. // 当媒体状态改变时,最后一个回调被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.