Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android java.lang.IllegalStateException MediaPlayer.isPlaying [closed]

I published my app and on some phones like Galaxy Nexus or HTC Explorer where my APP crashes.

I tested on many phones and app worked perfectly.

Can you explain me why is this happening and how to fix it ?

ERROR

java.lang.IllegalStateException
at android.media.MediaPlayer.isPlaying(Native Method)
at com.mario.kvizoman.SoloIgra.novopitanjce(SoloIgra.java:922)
at com.mario.kvizoman.SoloIgra.onClick(SoloIgra.java:901)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3768)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)

CODE

if(reptimer!=null) {
    if(reptimer.isPlaying()) {
        reptimer.stop();
    }
}

onCreate reptimer is

reptimer = MediaPlayer.create(SoloIgra.this, R.raw.napeto);
like image 840
mario Avatar asked Mar 31 '13 15:03

mario


2 Answers

According to the Android documentation: "IllegalStateException if the internal player engine has not been initialized or has been released."

So ensure your MediaPlayer is initialized, and you don't use the released one.

like image 98
Taras Avatar answered Oct 13 '22 16:10

Taras


From your code, since repTimer.isPlaying() is getting invoked, I assume that the JAVA repTimer object is not NULL. However, IllegalStateException is triggered when the native MediaPlayer object is NULL (Reference: http://androidxref.com/4.2.2_r1/xref/frameworks/base/media/jni/android_media_MediaPlayer.cpp#380 ). Hence, there is some mismatch between your JAVA states and native states.

P.S: You may want to check the code prior the position pasted in this question. In some earlier method call, the native object has been destroyed which is not reflected in your JAVA object state.

like image 24
Ganesh Avatar answered Oct 13 '22 16:10

Ganesh