Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android : media player - pause called in state 8

Tags:

android

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
like image 388
iappmaker Avatar asked Dec 16 '22 12:12

iappmaker


2 Answers

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).

like image 161
Jebasuthan Avatar answered Dec 30 '22 05:12

Jebasuthan


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();
}

}
like image 32
Mohamed Khalifa Avatar answered Dec 30 '22 04:12

Mohamed Khalifa