[Android] Avoid losing navigation when playing a video as audio

Nicolas Pomepuy git at videolan.org
Fri Mar 12 09:11:04 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Mar 12 09:54:55 2021 +0100| [325018f6d24c5f32d6492639ffb5e2b19a238807] | committer: Nicolas Pomepuy

Avoid losing navigation when playing a video as audio

Fixes #1665

> https://code.videolan.org/videolan/vlc-android/commit/325018f6d24c5f32d6492639ffb5e2b19a238807
---

 application/vlc-android/src/org/videolan/vlc/PlaybackService.kt        | 2 +-
 application/vlc-android/src/org/videolan/vlc/RecommendationsService.kt | 1 +
 application/vlc-android/src/org/videolan/vlc/StartActivity.kt          | 2 +-
 .../vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt  | 3 ++-
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index f882236a9..e2c4f046c 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -216,7 +216,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         get() {
             return when {
                 playlistManager.player.isVideoPlaying() -> {//PIP
-                    val notificationIntent = Intent(this, VideoPlayerActivity::class.java)
+                    val notificationIntent = Intent(this, VideoPlayerActivity::class.java).apply { putExtra(VideoPlayerActivity.FROM_EXTERNAL, true) }
                     PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
                 }
                 playlistManager.videoBackground || canSwitchToVideo() && !currentMediaHasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) -> {//resume video playback
diff --git a/application/vlc-android/src/org/videolan/vlc/RecommendationsService.kt b/application/vlc-android/src/org/videolan/vlc/RecommendationsService.kt
index 832e093b1..2d567728c 100644
--- a/application/vlc-android/src/org/videolan/vlc/RecommendationsService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/RecommendationsService.kt
@@ -92,6 +92,7 @@ class RecommendationsService : IntentService("RecommendationService"), Coroutine
         intent.putExtra(PLAY_EXTRA_ITEM_LOCATION, mw.uri)
         intent.putExtra(PLAY_EXTRA_ITEM_TITLE, mw.title)
         intent.putExtra(PLAY_EXTRA_FROM_START, false)
+        intent.putExtra(VideoPlayerActivity.FROM_EXTERNAL, true)
         return PendingIntent.getActivity(this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
index 6d26fb543..646bb7fcf 100644
--- a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
@@ -221,7 +221,7 @@ class StartActivity : FragmentActivity() {
         }
         if (Permissions.canReadStorage(applicationContext) || getStoragePermission()) when {
             intent.type?.startsWith("video") == true -> try {
-                startActivity(intent.setClass(this at StartActivity, VideoPlayerActivity::class.java))
+                startActivity(intent.setClass(this at StartActivity, VideoPlayerActivity::class.java).apply { putExtra(VideoPlayerActivity.FROM_EXTERNAL, true) })
             } catch (ex: SecurityException) {
                 intent.data?.let { MediaUtils.openMediaNoUi(it) }
             }
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 f00ef2b2d..b6aaa32a3 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
@@ -1342,7 +1342,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         if (service == null) return
         switchingView = true
         // Show the MainActivity if it is not in background.
-        if (showUI) {
+        if (showUI && intent.getBooleanExtra(FROM_EXTERNAL, false)) {
             val i = Intent().apply {
                 setClassName(applicationContext, if (isTv) TV_AUDIOPLAYER_ACTIVITY else MOBILE_MAIN_ACTIVITY)
             }
@@ -2064,6 +2064,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         private const val EXTRA_POSITION = "extra_position"
         private const val EXTRA_DURATION = "extra_duration"
         private const val EXTRA_URI = "extra_uri"
+        const val FROM_EXTERNAL = "from_external"
         private const val RESULT_CONNECTION_FAILED = Activity.RESULT_FIRST_USER + 1
         private const val RESULT_PLAYBACK_ERROR = Activity.RESULT_FIRST_USER + 2
         private const val RESULT_VIDEO_TRACK_LOST = Activity.RESULT_FIRST_USER + 3



More information about the Android mailing list