I am using the media player in my app for some short sounds. Though I do not find any problem / crash in my app, I could see some of the following error messages.. Please help me to resolve this.
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
You could use simple if-check to handle the pausing. Try this:
MediaPlayer mp = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/jaihind.mp3"));
if(mp.isPlaying()) {
mp.pause();
} else {
mp.start();
}
Note:
mp = MediaPlayer.create(...);
is already preparing the MediaPlayer returned, so you cannot call prepare
(or its variants) again (and there is no need for onPreparedListener as well).
I think you have to use this
public class Sound extends Activity{
MediaPlayer mp;
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mp.release();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With