ExoPlayer StyledPlayerView控制器分步隐藏问题求助:如何实现所有控件2秒后同步消失
Hey there! Let's figure out why your ExoPlayer controller isn't hiding all controls at the same time after the 2-second timeout you set.
The Problem Recap
You've set controllerShowTimeoutMs = 2000 on your StyledPlayerView, but instead of all controls hiding together after 2 seconds of inactivity, the progress bar disappears first, followed by the rest of the controls another 2 seconds later. You want everything to hide in sync.
Likely Root Cause
This usually happens because your custom controller layout (exo_control_layout_main) has separate hiding logic for the progress bar (or DefaultTimeBar) that doesn't match the global timeout you set on the StyledPlayerView. The progress bar might have its own default hide delay that's overriding the global setting.
Step-by-Step Solutions
1. Sync the Progress Bar's Hide Delay
Open your exo_control_layout_main layout file, find the DefaultTimeBar (it's usually tagged with @id/exo_progress), and explicitly set its hide delay to match your global timeout:
<com.google.android.exoplayer2.ui.DefaultTimeBar android:id="@id/exo_progress" android:layout_width="match_parent" android:layout_height="wrap_content" app:hide_delay="2000" /> <!-- Match this to your controllerShowTimeoutMs value -->
This ensures the progress bar follows the same 2-second timeout as the rest of the controls.
2. Check for Manual Visibility Controls
Double-check your Fragment code to make sure you aren't manually toggling the progress bar's visibility somewhere. Any code that calls setVisibility() on the progress bar independently will break the sync with the controller's global timeout.
3. Verify Controller Configuration
Ensure your StyledPlayerView settings are consistent and no later code overrides them:
// Set timeout first exoPlayerView.controllerShowTimeoutMs = 2000 // Disable auto-show on playback start exoPlayerView.controllerAutoShow = false
You can also add a visibility listener to debug state changes:
exoPlayerView.setControllerVisibilityListener { visibility -> Log.d("PlayerController", "Controller visibility: $visibility") // Check individual child views here to track when they hide }
4. Test with Default Controller
To rule out custom layout issues, temporarily remove the app:controller_layout_id attribute from your StyledPlayerView XML and use the default controller. If controls hide in sync with the default layout, the problem lies in your custom layout's configuration.
5. Update ExoPlayer
Older ExoPlayer versions might have bugs related to custom controller hiding logic. Upgrade to the latest stable version to see if the issue resolves itself.
Final Notes
Most of the time, this sync issue comes down to mismatched hide delays in the custom controller layout. Aligning the progress bar's delay with the global controller timeout should fix the problem.
内容的提问来源于stack exchange,提问作者Akhil Hothi

