SimpleExoPlayerView定制:设置背景透明及控件始终可见
Hey there! Let's sort out those two customization needs for your ExoPlayer setup. Here's how to address each one clearly:
1. Change the Background to Transparent
You can update this either directly in your XML layout or programmatically in your code:
Option 1: XML Layout Modification
Just add the android:background attribute to your SimpleExoPlayerView and set it to transparent. Here's your updated layout code:
<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" />
Option 2: Programmatic Setup
If you prefer setting it in code (maybe for dynamic changes), use this line after initializing your SimpleExoPlayerView:
// Assuming you've initialized your player view like this: SimpleExoPlayerView playerView = findViewById(R.id.video_view); playerView.setBackgroundColor(Color.TRANSPARENT);
Don't forget to import android.graphics.Color if you go this route.
2. Keep the Player Controls Always Visible
By default, SimpleExoPlayerView hides its controls after a short period of inactivity. To disable this auto-hide behavior and keep controls visible at all times, use these two methods:
// Disable auto-hide when the user touches the screen playerView.setControllerHideOnTouch(false); // Set timeout to 0 so controls never automatically hide playerView.setControllerShowTimeoutMs(0);
Alternatively, you can also explicitly force controls to stay visible with:
playerView.setShowControls(true);
Combining these ensures your player interface stays visible without requiring user touches to bring it back.
内容的提问来源于stack exchange,提问作者Sophie

