danylovolokh / VideoPlayerManager

This is a project designed to help controlling Android MediaPlayer class. It makes it easier to use MediaPlayer ListView and RecyclerView. Also it tracks the most visible item in scrolling list. When new item in the list become the most visible, this library gives an API to track it.
3.15k stars 747 forks source link

RuntimeException: this should be called in Main Thread #78

Open amanzan opened 7 years ago

amanzan commented 7 years ago

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)

itzharDev commented 6 years ago

same problem

paolomoschini commented 6 years ago

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 6 years ago

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

Thanks

paolomoschini commented 6 years ago

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

dup23 commented 6 years ago

It works ! Thanks @paolomoschini