4

我在我的应用程序中使用媒体播放器播放一些简短的声音。虽然我在我的应用程序中没有发现任何问题/崩溃,但我可以看到以下一些错误消息。请帮我解决这个问题。

03-23 22:53:16.229: E/MediaPlayer(19185): pause called in state 8
03-23 22:53:16.229: E/MediaPlayer(19185): error (-38, 0) 
03-23 22:53:16.449: E/MediaPlayer(19185): Error (-38,0)
03-23 22:53:16.449: D/OpenGLRenderer(19185): Flushing caches (mode 0) 
03-23 22:53:16.459: D/OpenGLRenderer(19185): Flushing caches (mode 0)
03-23 22:53:17.759: D/OpenGLRenderer(19185): Flushing caches (mode 0) 
03-23 22:53:17.809: W/MediaPlayer-JNI(19185): MediaPlayer finalized without being released
03-23 22:53:17.809: W/MediaPlayer-JNI(19185): MediaPlayer finalized without being released
03-23 22:53:17.809: W/MediaPlayer-JNI(19185): MediaPlayer finalized without being released
4

3 回答 3

11

您可以使用简单的 if-check 来处理暂停。尝试这个:

MediaPlayer mp = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/jaihind.mp3"));
if(mp.isPlaying()) {
    mp.pause();
} else {
    mp.start();
}

笔记:

mp = MediaPlayer.create(...);

已经在准备返回的 MediaPlayer,因此您不能prepare再次调用(或其变体)(也不需要 onPreparedListener)。

于 2014-03-14T10:20:05.777 回答
1

我认为你必须使用这个

 public class Sound extends Activity{

MediaPlayer mp;

    @Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    mp.release();
}

}
于 2013-03-23T17:58:45.043 回答
0

mp.release(); does the trick. [ instead of mp.pause(); ]

于 2013-12-06T02:16:39.100 回答