重复播放后媒体播放器错误 (-19,0) [英] Mediaplayer error (-19,0) after repeated plays
问题描述
我有一个游戏,当关卡完成时会播放声音.开始时一切正常,但在重复级别 10 或 20 次后,logcat 突然报告:MediaPlayer 错误 (-19,0)"和/或MediaPlayer start 在状态 0 中调用"并且不再发出声音.
I have a game in which a sound plays when a level is completed. Everything works fine to start with but after repeating a level 10 or 20 times the logcat suddenly reports: "MediaPlayer error (-19,0)" and/or "MediaPlayer start called in state 0" and the sounds are no longer made.
我原本有 mp3 格式的所有声音,但在阅读 ogg 可能更可靠后,我将它们全部转换为 ogg,但错误似乎完全相同.
I originally had the all sounds in mp3 format but, after reading that ogg may be more reliable, I converted them all to ogg, but the errors appeared just the same.
知道如何解决这个问题吗?
Any idea how I can fix this problem?
推荐答案
我也遇到了同样的问题,我通过添加以下代码来释放播放器解决了:
I was getting the same problem, I solved it by adding the following code to release the player:
mp1 = MediaPlayer.create(sound.this, R.raw.pan1);
mp1.start();
mp1.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.release();
};
});
这篇关于重复播放后媒体播放器错误 (-19,0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!