Search code examples
androidexoplayer2.x

Android Exoplayer SimpleExoPlayerView Play/Pause events


Is there a way to hook into the Play/Pause click events of the SimpleExoPlayerView controls? I'm trying to hookup chromecast to my play activity and i need to be able to respond to play events to determine if exoplayer should play the content or it should be sent to chromecast.

I thought onPlayerStateChanged might help with this but i can't see a ExoPlayer.STATE_PLAYING state.


Solution

  • Try this solution:

    SimpleExoPlayerView simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.simpleExoView);
            simpleExoPlayerView.setControlDispatcher(new PlaybackControlView.ControlDispatcher() {
                @Override
                public boolean dispatchSetPlayWhenReady(ExoPlayer exoPlayer, boolean b) {
    
                // implement what you need
    
                return b;
            }
    
            @Override
            public boolean dispatchSeekTo(ExoPlayer exoPlayer, int i, long l) {
                return false;
            }
        });