Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExoPlayerSimpleView updating not on the ui thread and crushing the app #4439

Closed
OfekRegev opened this issue Jun 27, 2018 · 5 comments
Closed
Assignees
Labels

Comments

@OfekRegev
Copy link

OfekRegev commented Jun 27, 2018

when the exoplayer is attached to the PlaybackControlView and the player is prepared and ready to play then when I'm calling player.setPlayWhenReady(true) not from the ui thread I get this crush -

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6817)
at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:940)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
at android.view.View.requestLayout(View.java:18794)
at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:360)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.requestLayout(View.java:18794)
at android.view.View.setFlags(View.java:10638)
at android.view.View.setVisibility(View.java:7437)
at android.widget.ImageView.setVisibility(ImageView.java:1497)
at com.google.android.exoplayer2.ui.PlaybackControlView.updatePlayPauseButton(PlaybackControlView.java:639)
at com.google.android.exoplayer2.ui.PlaybackControlView.access$1100(PlaybackControlView.java:172)
at com.google.android.exoplayer2.ui.PlaybackControlView$ComponentListener.onPlayerStateChanged(PlaybackControlView.java:1078)
at com.google.android.exoplayer2.ExoPlayerImpl.setPlayWhenReady(ExoPlayerImpl.java:171)
at com.google.android.exoplayer2.SimpleExoPlayer.setPlayWhenReady(SimpleExoPlayer.java:627)
at com.music.ofek.iplay.Services.PlayerService.handleMessage(PlayerService.java:173)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)

@andrewlewis
Copy link
Collaborator

Discussed with @tonihei. We'll look at posting to the main thread for these callbacks. Thanks for reporting this!

@OfekRegev
Copy link
Author

OfekRegev commented Jun 27, 2018

I have updated my issue comment. this is happening when using PlaybackControlView, I'm using PlaybackControlView and not SimpleExoPlayerView. I don't know if it's happening on SimpleExoPlayerView either so it's for you to check it out too.
@andrewlewis

@andrewlewis
Copy link
Collaborator

This may actually need to be fixed in a different way (TBD).

Out of interest, would it be feasible for you to move all calls to the player onto your app's main thread? If this is difficult it would be useful to know why. Thanks.

@OfekRegev
Copy link
Author

OfekRegev commented Jun 27, 2018

It's exactly what I did. but it's an error prone to do so because of 2 reasons -

  1. It's much harder for me to know which method of the player will directly update the view and which not.
  2. If I'm forgetting to do so anywhere in my code and it won't be found in the QA(which it's happening from time to time) even 1 call could crash my app.

as I see it it's much easier for you to manage the threads for the UI operations than it for me...

@tonihei
Copy link
Collaborator

tonihei commented Jun 27, 2018

Thanks for the feedback. In the current version, we always require to access the player from one thread only (see here (under "threading model") for a summary of our requirements).

From what you describe it seems your app should be using the main thread to make the call to setPlayWhenReady.

And, unfortunately, our UI components do not support using the player from any background thread at the moment. We need to establish how common this usage pattern is first, before deciding whether or not we are going to handle such situations.

ojw28 pushed a commit that referenced this issue Sep 17, 2018
ExoPlayer can be run on a background thread, but some components (UI and IMA)
only support players on the main thread. This adds some documentation and
assertions for that.

To simplify assertions, this also moves the getApplicationLooper method from
ExoPlayer to Player.

Issue:#4439

-------------
Created by MOE: https:/google/moe
MOE_MIGRATED_REVID=213280359
@tonihei tonihei closed this as completed Sep 24, 2018
@google google locked and limited conversation to collaborators Jan 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants