Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I ran into your issue, Skyler.</p> <p>You are correct. The documentation shows no invalid states for mediaPlayer.reset(), but that isn't the first inaccuracy in the documentation.</p> <p>What I noticed is that the list of VALID states doesn't say "Any"; it lists every specific state except for two: Preparing and End.</p> <p>I experimented, but could not cause IllegalStateException to be thrown in my attempts to call release() while the MediaPlayer is hopefully in the Preparing state (using prepareAsync()). I won't guarantee it doesn't happen, but I couldn't make it happen. What I did see in that instance were the following log messages:</p> <pre><code>04-11 11:41:54.740: E/MediaPlayer(4930): error (1, -2147483648) 04-11 11:41:54.748: E/MediaPlayer(4930): Error (1,-2147483648) </code></pre> <p>Yes, both error messages appear, one right after the other--one with lowercase "error" and one with uppercase "Error," but no Exception is thrown.</p> <p>However, if I call reset() after release() then I get the error:</p> <pre><code>04-11 11:45:05.232: E/AndroidRuntime(5046): FATAL EXCEPTION: main 04-11 11:45:05.232: E/AndroidRuntime(5046): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.helloandroid/com.android.helloandroid.HelloAndroidActivity}: java.lang.RuntimeException: java.lang.IllegalStateException 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.app.ActivityThread.access$1500(ActivityThread.java:124) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.os.Handler.dispatchMessage(Handler.java:99) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.os.Looper.loop(Looper.java:123) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.app.ActivityThread.main(ActivityThread.java:3806) 04-11 11:45:05.232: E/AndroidRuntime(5046): at java.lang.reflect.Method.invokeNative(Native Method) 04-11 11:45:05.232: E/AndroidRuntime(5046): at java.lang.reflect.Method.invoke(Method.java:507) 04-11 11:45:05.232: E/AndroidRuntime(5046): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-11 11:45:05.232: E/AndroidRuntime(5046): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-11 11:45:05.232: E/AndroidRuntime(5046): at dalvik.system.NativeStart.main(Native Method) 04-11 11:45:05.232: E/AndroidRuntime(5046): Caused by: java.lang.RuntimeException: java.lang.IllegalStateException 04-11 11:45:05.232: E/AndroidRuntime(5046): at com.android.helloandroid.HelloAndroidActivity.crashMediaPlayer(HelloAndroidActivity.java:423) 04-11 11:45:05.232: E/AndroidRuntime(5046): at com.android.helloandroid.HelloAndroidActivity.onCreate(HelloAndroidActivity.java:87) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660) 04-11 11:45:05.232: E/AndroidRuntime(5046): ... 11 more 04-11 11:45:05.232: E/AndroidRuntime(5046): Caused by: java.lang.IllegalStateException 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.media.MediaPlayer._reset(Native Method) 04-11 11:45:05.232: E/AndroidRuntime(5046): at android.media.MediaPlayer.reset(MediaPlayer.java:1112) 04-11 11:45:05.232: E/AndroidRuntime(5046): at com.android.helloandroid.HelloAndroidActivity.crashMediaPlayer(HelloAndroidActivity.java:421) 04-11 11:45:05.232: E/AndroidRuntime(5046): ... 14 more </code></pre> <p>So The Modern Ink's guess was correct. MediaPlayer.reset() throws IllegalStateException in the End state (which occurs after release() is called).</p> <p>In my case, I discovered I was calling release() on onPause(), but did nothing to initialize the MediaPlayer again in onResume(). Hence, it was in the End state when I called reset();</p> <p>Per <a href="http://developer.android.com/reference/android/media/MediaPlayer.html" rel="noreferrer">http://developer.android.com/reference/android/media/MediaPlayer.html</a>, </p> <blockquote> <p>Once the MediaPlayer object is in the End state, it can no longer be used and there is no way to bring it back to any other state.</p> </blockquote> <p>That means you need to create the MediaPlayer all over again, starting with mediaPlayer = new MediaPlayer() or one of the mediaPlayer.onCreate() methods. Or be careful about when you call release().</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload