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 in the Playlist will be playing and when using previous the previous video in the playlist will be playing and so on. I am using the Custom Layout, it changes the design but not listen for these events(next, previous etc). here is my code:-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="200dp"
app:resize_mode="fill"
app:controller_layout_id="@layout/custom_controls"
app:player_layout_id="@layout/custom_player_view"
app:surface_type="texture_view"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_marginTop="220dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
I have added the list of Mediasource in ConcatenatingMediaSource. It is working but I am to change the layout also, that why I need a listener for every control in ExoPlayer. I see this link. So I know onPositionDiscontinuity() method calls every time when the user clicks on next, previous, rewind, forward button in ExoPlayer But I want listener for each button so I can perform the appropriate action??
thanks
Show activity on this post. 3] Just check by clicking next button from the media controller if that works then you are done, now the videos will be played automatically once finished the current one.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With