danylovolokh/VideoPlayerManager

RuntimeException: this should be called in Main Thread

amanzan opened this issue · 5 comments

I get an exception right after running the sample project, without any modification:

Process: com.volokh.danylo.videolist, PID: 17239 java.lang.RuntimeException: this should be called in Main Thread at com.volokh.danylo.video_player_manager.ui.MediaPlayerWrapper.onVideoSizeChanged(MediaPlayerWrapper.java:214) at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3270) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

same problem

In MediaPlayerWrapper change this:

  private boolean inUiThread() {
        return Thread.currentThread().getId() == 1;
    }

with this:

private boolean inUiThread() {
   return Thread.currentThread() == Looper.getMainLooper().getThread();
}
dup23 commented

Hi,
I cannot modify MediaPlayerWrapper.java file because it is read-only, how can i fix this problem ?

Thanks

@dup23 You should download the entire source code and include it in your project to be able to modify it properly

dup23 commented

It works ! Thanks @paolomoschini