Exoplayer throws player is accessed on the wrong thread Exception


when I use exoplayer I get a player is accessed on the wrong thread error. How can I solve this?

Non-fatal Exception: java.lang.IllegalStateException: Player is accessed on the wrong 
Current thread: 'main'
Expected thread: 'ConnectivityThread'
See https://exoplayer.dev/issues/player-accessed-on-wrong-thread

The player is started as a service via my BackgroundAudioService.class.

exoPlayer = new ExoPlayer.Builder(getApplicationContext()

In the main thread my looper is running, the
which updates the UI via exoplayer.getCurrentPosition().

public final Runnable updatePosition = new Runnable() {
    public void run() {
        position  = BackgroundAudioService.getCurrentPostion();

myHandler.postDelayed(updatePosition, myHandlerSleep);

I don’t know how to solve this problem (which occurs just sometimes), please help.



I solved this by calling the status via a handler in the player’s event listener. Starting a runnable from the listener which runs only when player.isPlaying() == true.

     player.addListener(new Player.Listener() {
        public void onEvents(Player player, Player.Events events) {
            Player.Listener.super.onEvents(player, events);

            if (events.contains(Player.EVENT_IS_PLAYING_CHANGED)) {
                if (player.isPlaying()) {

                } else {


    public Runnable getCurrentPositionTask = new Runnable() {

    public void run() {
        if (exoPlayer != null) {
            currentPostion = exoPlayer.getCurrentPosition();

The UI calls the current position the same way in a runnable.

I can’t say whether this is the best way. but it’s going well.


Answered By – GGK stands for Ukraine

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published