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

EventListener isn't called in correct thread's looper #4332

Closed
Khang-NT opened this issue May 31, 2018 · 2 comments
Closed

EventListener isn't called in correct thread's looper #4332

Khang-NT opened this issue May 31, 2018 · 2 comments
Assignees

Comments

@Khang-NT
Copy link
Contributor

Issue description

The document of method Player#addListener said:

Register a listener to receive events from the player. The listener's methods will be called on the thread that was used to construct the player. However, if the thread used to construct the player does not have a Looper, then the listener will be called on the main thread.

I did construct new SimpleExoPlayer instance within my own Looper (which is not Looper.mainLooper()). But when I call prepare() media source on main thread, ExoPlayer callback to all listeners within main thread instead of using my looper to dispatch the event.

I can see the method ExoPlayerImpl#updatePlaybackInfo invoke listener's methods within caller thread, regardless the thread was used to construct the player.

Reproduction steps

  • Create HandlerThread and then create ExoPlayer object within HandlerThread#onLooperPrepared
  • Add a listener: Player#addListener
  • Switch to main thread and call Player#prepare

Link to test content

Can test with demo app.

Version of ExoPlayer being used

2.8.0

@Khang-NT Khang-NT changed the title Events are not dispatched in correct Looper thread EventListener isn't called in correct thread's looper May 31, 2018
@tonihei
Copy link
Collaborator

tonihei commented May 31, 2018

That's more or less working as intended. ExoPlayer also requires you to call all methods on the thread the player was created on (or the main thread if it doesn't have a looper). See also the points under "threading model" here: http://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ExoPlayer.html.

The documentation is not as clear as it should be, and based on the discussion in #4278, we also just changed it to spell out the requirements more explicitly.

@ojw28
Copy link
Contributor

ojw28 commented Jun 5, 2018

Threading requirements were clarified in 2813c06. We'll also update the developer guide.

In addition, we're planning a change that will allow you to specify a Looper when instantiating the player, which will add a little more flexibility. Follow #4278 for updates.

@ojw28 ojw28 closed this as completed Jun 5, 2018
@google google locked and limited conversation to collaborators Nov 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants