2

I am using PlayFragment for playing video in AndroidTV. I want to hide the controlls like play/pause/fastforward/progressbar.

How can i do it ?

if anyone knows then please help. I am using below sample :

[https://github.com/googlesamples/androidtv-Leanback.git][1]

there are some menthods in PlayBackFragment like

setControlsOverlayAutoHideEnabled(false)
hideControlsOverlay(true);

but no works. Can anyonen help me ?

nitin tyagi
  • 456
  • 1
  • 4
  • 19
  • Do you want the controls hidden when the fragment first starts playing? Be default the controls fade away after a small delay. – Benjamin Nov 10 '17 at 15:20

3 Answers3

5

The video fragment itself is responsible for showing and hiding the controls, and since your fragment inherits from VideoSupportFragment/VideoFragment you can simply override the method showControlsOverlay(..) and keep it empty (don't call the super method)

@Override
public void showControlsOverlay(boolean runAnimation) {
    // We will do nothing here, and thus controls will never be shown
}

You also have to call hideControlsOverlay(false) once when setting up the player:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ...

    hideControlsOverlay(false);
}
Hejazi
  • 16,587
  • 9
  • 52
  • 67
  • This works. But it also removes all the playback controls done from the dpad. Is there any way I can just hide it from the ui but have the functionality still intact when controlled from dpad. – AndroidDev Mar 08 '21 at 07:39
  • @AndroidDev did you find any solution of that – Sundeep Badhotiya Oct 11 '22 at 11:13
  • @SundeepBadhotiya , Unfortunately no. I had to discard using PlayFragment from leanback and build my own fragment and handle exoplayer and Ui. A bit extra overhead. But it gave lot of flexibility to customize and control the Ui the way I want. – AndroidDev Oct 16 '22 at 14:01
2

To hide the controls when the video first starts you need to tell both the glue and the fragment not to show them.

If you look at the source of PlaybackTransportControls, on line 317, the controls check if fading is enabled and there is a host. If so, then it updates the visibility of the controls based on if the player is playing.

To test, in the leanback sample, look for the initializePlayer() method in the playback fragment. On line 166, it starts the player. When play happens, the glue tells the host (who talks to the fragment) and shows the controls. To prevent the controls being shown, setup the glue and the fragment to not show them:

private void initializePlayer() {
    ...
    // Setup the glue and fragment to not show controls when play starts.
    mPlayerGlue.setControlsOverlayAutoHideEnabled(false);
    hideControlsOverlay(false);

    play(mVideo);
    ...
}
Benjamin
  • 250
  • 1
  • 9
0

Have you tried calling fadeOut() from the PlaybackFragment?

Kyle Venn
  • 4,597
  • 27
  • 41