[Android] Fix videoAsAudio with videoRestore setting enabled

Duncan McNamara git at videolan.org
Wed Jan 31 07:20:34 UTC 2024


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Mon Jan 29 18:10:58 2024 +0100| [671cfbd6f14fc740048154b139d3d21f2842af06] | committer: Nicolas Pomepuy

Fix videoAsAudio with videoRestore setting enabled

Due to the introduction of the Force Video Restore setting,
when it was enabled, it would constantly restore video, breaking play as
audio. By adding this flag we can differentiate whether the video player
switched to audio because of the user leaving the app, of if the user
specifically pressed the play-as-audio button

> https://code.videolan.org/videolan/vlc-android/commit/671cfbd6f14fc740048154b139d3d21f2842af06
---

 application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt  | 2 +-
 .../vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt  | 2 ++
 application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt  | 2 +-
 .../src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt          | 3 +++
 4 files changed, 7 insertions(+), 2 deletions(-)

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 1fba96e4fa..2b2a60aa0f 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
@@ -306,7 +306,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) {
+                } else if (forceRestoreVideo && !PlaylistManager.playingAsAudio) {
                     onResumeToVideoClick()
                 }
         }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index c8570ed906..c3f9e9c396 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -110,6 +110,7 @@ import org.videolan.vlc.gui.helpers.UiTools.showPinIfNeeded
 import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate
 import org.videolan.vlc.interfaces.IPlaybackSettingsController
 import org.videolan.vlc.media.NO_LENGTH_PROGRESS_MAX
+import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.media.VideoResumeStatus
 import org.videolan.vlc.media.WaitConfirmation
 import org.videolan.vlc.repository.ExternalSubRepository
@@ -1598,6 +1599,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
     fun switchToAudioMode(showUI: Boolean) {
         if (service == null) return
         switchingView = true
+        PlaylistManager.playingAsAudio = showUI
         // Show the MainActivity if it is not in background.
         if (showUI && intent.getBooleanExtra(FROM_EXTERNAL, false)) {
             val i = Intent().apply {
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 48b5c02c37..8791c7df36 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -109,7 +109,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         private val mediaList = MediaWrapperList()
         fun hasMedia() = mediaList.size() != 0
         val repeating = MutableStateFlow(PlaybackStateCompat.REPEAT_MODE_NONE)
-
+        var playingAsAudio = false
     }
 
     private val medialibrary by lazy(LazyThreadSafetyMode.NONE) { Medialibrary.getInstance() }
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
index 43a73e492e..18707ccf2c 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/VideosViewModel.kt
@@ -39,6 +39,7 @@ import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.helpers.UiTools.addToPlaylist
 import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.media.MediaUtils
+import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.media.getAll
 import org.videolan.vlc.providers.medialibrary.FoldersProvider
 import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
@@ -134,6 +135,7 @@ class VideosViewModel(context: Context, type: VideoGroupingType, val folder: Fol
             return
         }
         mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
+        PlaylistManager.playingAsAudio = false
         val settings = Settings.getInstance(context)
         if (!fromStart && (settings.getBoolean(FORCE_PLAY_ALL_VIDEO, Settings.tvUI) || forceAll)) {
             when(val prov = provider) {
@@ -158,6 +160,7 @@ class VideosViewModel(context: Context, type: VideoGroupingType, val folder: Fol
     internal fun playAudio(activity: FragmentActivity?, media: MediaWrapper) {
         if (activity == null) return
         media.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
+        PlaylistManager.playingAsAudio = true
         MediaUtils.openMedia(activity, media)
     }
 



More information about the Android mailing list