Exoplayer: How to disable Timebar?

Created on 13 Mar 2018  路  4Comments  路  Source: google/ExoPlayer

I use Exoplayer for my project.

Beforte to play a video, I want to show a advertising with all controls disabled in player when the ad is playing.

I already disable all ImageButtons (next, prev, pause and etc...), but i having problem to do this to timebar. How can I disable the user interation with timebar?

question

All 4 comments

Hi @r3nan ,
I guess you are using the PlayerControlView, PlayerView, DefaultTimeBar, and try to use DefaultTimeBar.setEnabled(false) to disable the time-bar? The problem with this is: this will be overridden in PlayerControlView (it will reenable the time-bar if the content is seekable).

To fix this, I can come up with a few workarounds, but none of them seem to be too easy (not sure if anyone can have a better recommendation):
Easiest fix (I think):

  • Override DefaultTimeBar, add a flag to allow you to manually override setEnable().
  • Then override the exo_playback_control_view.xml file (see this post), and use the new custom TimeBar class instead of the DefaultTimeBar class.

Another way (a bit trickier):

  • Wrap the content MediaSource in a way that allow you to inject a non-seekable Timeline before you start playing the video. Then let it expose the normal Timeline when you start playing the video.

Btw, I'm not sure how you are displaying the ad. However, according to @andrewlewis, if you are using the IMA extension of ExoPlayer (see this post), it will take care of disabling time-bar when playing the ads.

Hi botaydotcom. Thank you for the answer.

How can I do this: "add a flag to allow you to manually override setEnable()"?

Hi @r3nan,
I haven't verified the code, but something like this will do:

  class ExtendedTimeBar extends DefaultTimeBar {
    private boolean enabled;
    private boolean forceDisabled;

    @Override
    public void setEnabled(boolean enabled) {
      this.enabled = enabled;
      super.setEnabled(!this.forceDisabled && this.enabled);
    }

    public void setForceDisabled(boolean forceDisabled) {
      this.forceDisabled = forceDisabled;
      setEnabled(enabled);
    }
  }

Cool! It worked very well for me =D Thank you for the support.

Was this page helpful?
0 / 5 - 0 ratings