For my alarm app, this error is coming only for Xiaomi Note 3 & Xiaomi Mi4 devices & working fine for all other devices including my personsal Xiaomi Redmi 3S.
Exception java.lang.RuntimeException: Unable to start activity
java.lang.IllegalStateException :
Caused by java.lang.IllegalStateException:
android.media.MediaPlayer._prepare (MediaPlayer.java)
android.media.MediaPlayer.prepare (MediaPlayer.java:1408)
android.app.Activity.performCreate (Activity.java:6912)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1126)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2877)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2985)
android.app.ActivityThread.-wrap14 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1635)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6692)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
Let's assume that you provide
data-source
beforeMediaPlayer.prepare()
Since
MediaPlayer.prepare()
blocks the main thread, which results in an exception. To prevent this, tryMediaPlayer.prepareAsync()
instead ofMediaPlayer.prepare()
. For this apporach readonPreparedListener()
andonErrorListener()
If this didn't help, please have a look at this, this and this