How to add Listener for next , previous , rewind and forward in Exoplayer

后端 未结 4 995
别跟我提以往
别跟我提以往 2021-01-13 11:10

I am working on ExoPlayer, I want to customize the ExoPlayer and listen for the Event next, previous, rewind, forward so that when the user clicks the next button next video

相关标签:
4条回答
  • 2021-01-13 11:38

    I use this link to customize the ExoPlayer for previous, next etc. You can implement your own logic to track all of these Events. It works for me.

    0 讨论(0)
  • 2021-01-13 11:48
     if you have not customized exoplayer
    
    
    
        if (currentPlayingVodPosition-1 == player.currentWindowIndex){
     Toast.makeText(this,"prev clicked",Toast.LENGTH_SHORT).show()
    
                        }
    if (currentPlayingVodPosition+1 == player.currentWindowIndex){
       Toast.makeText(this,"next clicked",Toast.LENGTH_SHORT).show()
    
                        }
    
    0 讨论(0)
  • 2021-01-13 11:54

    My approach

    Assumed, we are already create collection of media source, DASH or HLS.

    And using player view with SimpleExoPlayerView component. It will automatically have default control, prev, next, for example.

    I handle collection of media source with current window index with this exoPlayer.getCurrentWindowIndex() to back and forth media source.

    And you can check current index via this onTracksChanged method

    @Override
    public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    
    currentIndex = exoPlayer.getCurrentWindowIndex();
    
    }
    

    You can look this file for implementation these control.

    Hope this help.

    0 讨论(0)
  • 2021-01-13 12:02

    You might be able to add a ExoPlayer.Listener() and use constants from the PlaybackstateCompat class.

    Override the onPlayerStateChanged listener and check the playbackState with rewind/fastforward/etc

     player.addListener(new ExoPlayer.Listener() {
                @Override
                public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
                    if (playbackState == PlaybackStateCompat.STATE_FAST_FORWARDING) {
                        //do something                 
                    }
                    if (playbackState == PlaybackStateCompat.STATE_REWINDING) {
                        //do something else               
                    }
                }
    
                @Override
                public void onPlayWhenReadyCommitted() {
    
                }
    
                @Override
                public void onPlayerError(ExoPlaybackException error) {
                    mExoPlayer.stop();
    
                }
            });
    

    Also:

    1. STATE_SKIPPING_TO_NEXT
    2. STATE_SKIPPING_TO_PREVIOUS
    0 讨论(0)
提交回复
热议问题