How to hide control buttons in ExoPlayer2
Asked Answered
M

11

52

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?

Malisamalison answered 16/2, 2017 at 1:47 Comment(1)
Checkout this may helps for Jetpack Compose: https://mcmap.net/q/353654/-play-video-from-uri-in-jetpack-compose-androidAmbary
C
92

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"/>
Clout answered 8/3, 2017 at 8:45 Comment(3)
when using app:use_controller="false" then click event not working on the exoplayer2Kriemhild
I just want to play video, the clicklistener is still showing the control even with use_controller set to falseLab
Checkout this may helps for Jetpack Compose: https://mcmap.net/q/353654/-play-video-from-uri-in-jetpack-compose-androidAmbary
S
42

Simply use this

exoPlayerView.setUseController(false);
Snath answered 13/3, 2018 at 12:33 Comment(4)
how to hide the next button only from the controller?Casabonne
@MuhammedHaris try asking that in a new questionDeclassify
Checkout this may helps for Jetpack Compose: https://mcmap.net/q/353654/-play-video-from-uri-in-jetpack-compose-androidAmbary
After applying setUseController(false);. it's onclicklistener method is not working.Heaviside
D
28

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-

Declassify answered 5/8, 2019 at 20:31 Comment(0)
S
11
exoPlayerView.setUseController(false);
Saphena answered 11/3, 2018 at 5:18 Comment(0)
M
7

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

Mayhem answered 12/1, 2022 at 16:39 Comment(1)
VideoPlayer method works for me to stop video by onDispose() Thanks! Mine simple method is something like : https://mcmap.net/q/353654/-play-video-from-uri-in-jetpack-compose-androidAmbary
M
6

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

mPlayerView.hideController();

Mimicry answered 15/11, 2018 at 8:26 Comment(0)
T
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()
                }
            }
        }
    }
Thatcher answered 5/9, 2017 at 13:37 Comment(0)
J
3

exoPlayerView.useController = false

Jiggermast answered 7/1, 2021 at 10:15 Comment(0)
A
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"/>
Ancohuma answered 16/6, 2020 at 8:11 Comment(0)
A
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
Absorb answered 17/4, 2023 at 8:31 Comment(0)
H
-4
controller.setVisibility(View.GONE);
controller.setVisibility(View.INVISIBLE); 

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

Histidine answered 16/2, 2017 at 2:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.