Mediaplayer.prepare()与IllegalStateException崩溃,仅适用于小米Note 3&小米Mi4

时间:2017-09-10 11:38:34

标签: android android-mediaplayer illegalstateexception

对于我的闹钟应用,此错误仅适用于小米Note 3 & 小米Mi4 设备&适用于所有其他设备,包括我的个人小米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)

1 个答案:

答案 0 :(得分:0)

假设您在data-source之前提供MediaPlayer.prepare()

由于MediaPlayer.prepare()阻塞主线程,因此会导致异常。要防止出现这种情况,请尝试使用MediaPlayer.prepareAsync()代替MediaPlayer.prepare()。对于此应用,请阅读onPreparedListener()onErrorListener()
如果这没有帮助,请查看thisthisthis