[Android] VideoPlayer: fix video resume after screen off
Duncan McNamara
git at videolan.org
Mon Jun 1 12:59:15 UTC 2026
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Fri May 29 18:07:41 2026 +0200| [4d32b8f7b47e4a1fec68e04cd20c8e9c4edc3344] | committer: Nicolas Pomepuy
VideoPlayer: fix video resume after screen off
It seems that with video in background enabled, and the restore video
from background setting enabled, when the screen is turned off, the
video player shuts down, and the audio player resumes, which triggers
onResumeToVideoClick(), which fails because the screen is off, then the
media's MEDIA_FORCE_AUDIO is set to true.
When reopening the app, it will detect that a video playback was
playing, try to reopen the video player, and in switchToVideo in
PlaylistModel, the condition to continue reopening the video player will
fail, because MEDIA_FORCE_AUDIO is true, and then nothing else happens.
The video player doesn't reopen, and the audio player doesn't know it
should open.
By adding the check to isInteractive, we ensure that
onResumeToVideoClick() isn't called when the screen is off, it then
doesn't fail, and when it is called again when the screen is turned on
again it will work, as MEDIA_FORCE_AUDIO hasn't been set to true.
> https://code.videolan.org/videolan/vlc-android/commit/4d32b8f7b47e4a1fec68e04cd20c8e9c4edc3344
---
.../src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 535cdaab82..f3e2e4cbec 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -21,11 +21,14 @@
package org.videolan.vlc.gui.audio
import android.Manifest
+import android.annotation.TargetApi
import android.content.Intent
import android.content.SharedPreferences
+import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
+import android.os.PowerManager
import android.os.Vibrator
import android.support.v4.media.session.PlaybackStateCompat
import android.text.Editable
@@ -95,6 +98,7 @@ import org.videolan.tools.setGone
import org.videolan.tools.setVisible
import org.videolan.vlc.PlaybackService
import org.videolan.vlc.R
+import org.videolan.vlc.VlcMigrationHelper
import org.videolan.vlc.databinding.AudioPlayerBinding
import org.videolan.vlc.gui.AudioPlayerContainerActivity
import org.videolan.vlc.gui.HeaderMediaListActivity
@@ -179,6 +183,13 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
private var currentChapters: Pair<MediaWrapper, List<MediaPlayer.Chapter>?>? = null
private lateinit var callback: SwipeDragItemTouchHelperCallback
+ private val isInteractive: Boolean
+ @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
+ get() {
+ val pm = requireContext().getSystemService<PowerManager>()!!
+ return if (VlcMigrationHelper.isLolliPopOrLater) pm.isInteractive else pm.isScreenOn
+ }
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
savedInstanceState?.let {
@@ -400,7 +411,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
if ( !forceRestoreVideo && restoreVideoTipCount < 4) {
UiTools.snacker(requireActivity(), R.string.return_to_video)
settings.putSingle(PREF_RESTORE_VIDEO_TIPS_SHOWN, restoreVideoTipCount + 1)
- } else if (forceRestoreVideo && !PlaylistManager.playingAsAudio) {
+ } else if (forceRestoreVideo && !PlaylistManager.playingAsAudio && isInteractive) {
onResumeToVideoClick()
}
}
More information about the Android
mailing list