我在我的应用程序中使用媒体播放器发出一些简短的声音.虽然我的应用程序中没有发现任何问题/崩溃,但我可以看到以下一些错误消息..请帮我解决此问题. 03-23 22:53:16.229: E/MediaPlayer(1
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您可以使用简单的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).