50

How to hide all controllers in ExoPlayer2 (start button, pause, and so on) that they did not exist, and the screen was always full.

I looked, there is simpleExoPlayerView.setUseController(true) method;

But it deactivate the player ...

public void setUseController (boolean useController) {
    this.useController = useController;
if (useController) {
      controller.setPlayer(player);
    } else {
      controller.hide();
      controller.setPlayer(null);
    }
}

How to hide or delete these components?

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Nurlan Kanimetov
  • 521
  • 1
  • 4
  • 4

11 Answers11

89

ExoPlayer-r2.2.0 used

videoView.hideController();
videoView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() {
    @Override
    public void onVisibilityChange(int visibility) {
        if(visibility == View.VISIBLE) {
            videoView.hideController();
        }
    }
});

or

app:use_controller="false" in Layout

<...
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...>

    <com.google.android.exoplayer2.ui.SimpleExoPlayerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:use_controller="false"/>
Emad Razavi
  • 1,903
  • 2
  • 17
  • 24
Junsu Lee
  • 1,481
  • 11
  • 7
40

Simply use this

exoPlayerView.setUseController(false);
karthik kolanji
  • 2,044
  • 5
  • 20
  • 56
27

Kotlin:

exoPlayerView.useController = false

Java:

exoPlayerView.setUseController(false);

XML:

app:use_controller="false"

Documentation: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/PlayerView.html#setUseController-boolean-

Westy92
  • 19,087
  • 4
  • 72
  • 54
11
exoPlayerView.setUseController(false);
rsc
  • 10,348
  • 5
  • 39
  • 36
6

PlayerView has a hideController method. you can call it like this:

mPlayerView.hideController();

linkaipeng
  • 483
  • 7
  • 9
6

A simple adaptation to Jetpack compose of this answer

@Composable
fun VideoPlayer(myVideo: MyVideo, modifier: Modifier = Modifier) {
    val context = LocalContext.current
    val exoPlayer = remember {
        ExoPlayer.Builder(context).build().apply {
            setMediaItem(myVideo.asMediaItem())
            repeatMode = ExoPlayer.REPEAT_MODE_ALL
            playWhenReady = true
            prepare()
            play()
        }
    }
    DisposableEffect(
        AndroidView(
            modifier = modifier,
            factory = {
                PlayerView(context).apply {
                    player = exoPlayer
                    useController = false
                    FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams
                            .MATCH_PARENT,
                        ViewGroup.LayoutParams
                            .MATCH_PARENT
                    )
                }
            }
        )
    ) {
        onDispose {
            exoPlayer.release()
        }
    }
}

This would be asMediaItem() extension function

private fun MyVideo.asMediaItem() =
    MediaItem.Builder()
        .setUri(url)
        .setMediaId("some-media-id")
        .setTag("some-video-tag")
        .setMediaMetadata(
            MediaMetadata.Builder().setDisplayTitle("Video").build()
        )
        .build()

and MyVideo class, which models a really basic video

data class MyVideo(val url: String, val previewImage: String)

The key line to remove the controls here is useController = false

voghDev
  • 5,641
  • 2
  • 37
  • 41
  • VideoPlayer method works for me to stop video by onDispose() Thanks! Mine simple method is something like : https://stackoverflow.com/a/71977304/3974530 – InsaneCat Apr 23 '22 at 06:13
5

To solve this problem I did this:

Code in Kotlin

simpleExoPlayerView.setControllerVisibilityListener { visibility ->
        val layout = activity.findViewById<LinearLayout>(R.id.ll_customPlayBackControlView)
        if (layout.tag != "IN_ANIMATION") {
            when (visibility) {
                View.GONE -> {
                    layout.tag = "IN_ANIMATION"
                    ex_fragmentVideoView.showController()
                    layout.animate().alpha(0F).setDuration(450L).withEndAction({ ex_fragmentVideoView.hideController(); layout.tag = "" }).start()
                }
                View.VISIBLE -> {
                    layout.animate().alpha(1F).setDuration(450L).start()
                }
            }
        }
    }
MarceloSouza
  • 429
  • 5
  • 10
2

In my case I wanted to only show the controller and hide the video screen. I used PlaybackControlView.

     <com.google.android.exoplayer2.ui.PlaybackControlView
            android:id="@+id/player_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/quantum_yellow"/>
GilbertS
  • 591
  • 8
  • 12
2

exoPlayerView.useController = false

ajaas azeez
  • 259
  • 4
  • 11
0

You should use new version implementation 'com.google.android.exoplayer:exoplayer:2.18.5'

Usage-1: Xml file : app:use_controller="false"

<com.google.android.exoplayer2.ui.StyledPlayerView
        android:id="@+id/playerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:show_subtitle_button="true"
        argType:fastforward_increment="15000"
        argType:resize_mode="fixed_width"
        argType:rewind_increment="15000"
        argType:show_buffering="when_playing"
        argType:show_fastforward_button="true"
        argType:show_next_button="false"
        argType:show_previous_button="false"
        argType:show_rewind_button="true"
        argType:show_subtitle_button="true"
        argType:use_artwork="true"
        app:use_controller="false"
        argType:use_sensor_rotation="true" />

Usage-2: You can use it in Activity like this.

 binding.playerView.useController = false
Halil Ozel
  • 2,482
  • 3
  • 17
  • 32
-4
controller.setVisibility(View.GONE);
controller.setVisibility(View.INVISIBLE); 

Use either of those to set visibilty. Android Documentation : Link

Dharan Aditya
  • 17
  • 1
  • 1
  • 4