[Android] Fix subtitles loaded from intent

Nicolas Pomepuy git at videolan.org
Tue Dec 1 10:19:03 CET 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Nov 30 14:35:05 2020 +0100| [7090f853d32ad0f1a0b18fb93b210cb79fcc8750] | committer: Nicolas Pomepuy

Fix subtitles loaded from intent

Fixes #1203

> https://code.videolan.org/videolan/vlc-android/commit/7090f853d32ad0f1a0b18fb93b210cb79fcc8750
---

 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt   | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

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 1d2a0475c..cc0cba819 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 kotlin.math.roundToInt
 @ExperimentalCoroutinesApi
 open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback, PlaylistAdapter.IPlayer, OnClickListener, OnLongClickListener, StoragePermissionsDelegate.CustomActionController, TextWatcher {
 
+    private var subtitlesExtraPath: String? = null
     private lateinit var startedScope : CoroutineScope
     var service: PlaybackService? = null
     lateinit var medialibrary: Medialibrary
@@ -1189,7 +1190,13 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
             when (event.type) {
                 MediaPlayer.Event.Playing -> onPlaying()
                 MediaPlayer.Event.Paused -> overlayDelegate.updateOverlayPausePlay()
-                MediaPlayer.Event.Opening -> forcedTime = -1
+                MediaPlayer.Event.Opening -> {
+                    forcedTime = -1
+                    if (!subtitlesExtraPath.isNullOrEmpty()) {
+                        service.addSubtitleTrack(subtitlesExtraPath!!, true)
+                        subtitlesExtraPath = null
+                    }
+                }
                 MediaPlayer.Event.Vout -> {
                     updateNavStatus()
                     if (event.voutCount > 0)
@@ -1682,8 +1689,8 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                 }
                 positionInPlaylist = extras.getInt(PLAY_EXTRA_OPENED_POSITION, -1)
 
-                val path = extras.getString(PLAY_EXTRA_SUBTITLES_LOCATION)
-                if (!path.isNullOrEmpty()) service.addSubtitleTrack(path, true)
+                subtitlesExtraPath = extras.getString(PLAY_EXTRA_SUBTITLES_LOCATION)
+                if (!subtitlesExtraPath.isNullOrEmpty()) service.addSubtitleTrack(subtitlesExtraPath!!, true)
                 if (intent.hasExtra(PLAY_EXTRA_ITEM_TITLE))
                     itemTitle = extras.getString(PLAY_EXTRA_ITEM_TITLE)
             }



More information about the Android mailing list