Exo player has a widget that handles the progress called
DefaultTimeBar
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@+id/exo_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Using this how-to programmatically seek to a particular position like 50% in android
Through inspecting the source code, it seems like
DefaultTimeBarcallsupdate()constantly to retrievebufferedPositionandpositionand draw the view accordingly. But it also has a couple of functions that callupdate()themselves and redraw everything. It is first initialized under the hood with acontextand a few other parameters likeAttributeSet.From here, it really depends on what you're willing to do with it. If you want to just seek the position in ExoPlayer (which I assume you already know), you can just call this
However, if you're miscellaneously using the view as a
Custom Viewand wanna update your DefaultTimeBar on your own. You need to understand how to instantiate it. OurDefaultTimeBarwill receivepositionandbufferedPositionvalue updates constantly from the class that instantiated it to begin with;PlayerControlView.Let's break it down quickly, how a DefaultTimeBar is instantiated and updated:
1- Instantiation:
As you can see, it takes a
context, a@Nullable AttributeSet, adefStyleAttrand a@Nullable timeBar AttributeSet. Of course this can be a little bit confusing at first, but for starters, try going with the sample line of code above to instantiate it. TheplaybackAttrsin the constructor are the same playbackAttrs passed from SimpleExoPlayer to PlayerControlView in order to instantiate it. If playbackAttrs are still a cause of confusion, please inspect the source code ofSimpleExoPlayer.2- Updating positions: After you have instantiated your DefaultTimeBar, you can constantly call these two functions on the instance you have
3- Modifying a DefaultTimeBar view that is inflated from the XML: I have no particular experience howsoever with manipulating the DefaultTimeBar, but I assume you can just pass the generated view as a DefaultTimeBar and store it in a variable, that is:
This MAY or MAY NOT work. DefaultTimeBar extends "View" so the casting may or may not work.
If you wanna seek to a particular position, always make sure you know the target position (For example, a result of a user-induced seeking), then call setPosition to update the DefaultTimeBar.