[Android] APContainer: fix AP not showing after screen off
Duncan McNamara
git at videolan.org
Fri Mar 21 05:54:24 UTC 2025
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed Mar 19 13:37:09 2025 +0100| [32a0a741c2ee85ee64434f3ab796a5aa1a3b0eb4] | committer: Nicolas Pomepuy
APContainer: fix AP not showing after screen off
When playing a video with "Play in background" enabled, if the screen is
switched off, the player will switch to audio, triggering a
ACTION_SHOW_PLAYER scheduled with a 100L delay that has been there since
java.
Because the screen is switched off, onPause is called, triggering a
cancellation of ACTION_SHOW_PLAYER in the LifecyleAwareScheduler,
before it can execute it.
To ensure ACTION_SHOW_PLAYER is executed when switching the screen
back on, a flag is set and checked in onResume to call
showAudioPlayerImpl
> https://code.videolan.org/videolan/vlc-android/commit/32a0a741c2ee85ee64434f3ab796a5aa1a3b0eb4
---
.../src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
index 152a63ce61..f3a93fb394 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
@@ -105,6 +105,7 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener, Sched
private var scanProgressBar: ProgressBar? = null
private lateinit var resumeCard: Snackbar
private var preventRescan = false
+ private var showAudioPlayerWhenResumed = false
private var playerShown = false
val tipsDelegate: AudioTipsDelegate by lazy(LazyThreadSafetyMode.NONE) { AudioTipsDelegate(this) }
@@ -511,6 +512,8 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener, Sched
else
applyMarginToProgressBar(0)
setContentBottomPadding()
+ if (showAudioPlayerWhenResumed)
+ showAudioPlayerImpl()
super.onResume()
}
@@ -588,10 +591,14 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener, Sched
private fun showAudioPlayer() {
if (isFinishing) return
scheduler.scheduleAction(ACTION_SHOW_PLAYER, 100L)
+ // due to the 100L delay when scheduling ACTION_SHOW_PLAYER
+ // if switching screen off, it can be canceled, this ensures that onResume the player is shown
+ showAudioPlayerWhenResumed = true
}
private fun showAudioPlayerImpl() {
if (isFinishing) return
+ showAudioPlayerWhenResumed = false
if (!isAudioPlayerReady) initAudioPlayer()
if (audioPlayerContainer.visibility != View.VISIBLE) {
audioPlayerContainer.visibility = View.VISIBLE
More information about the Android
mailing list