[Android] Show messages in the subtitle if seek fails

Robert Stone git at videolan.org
Tue Nov 9 08:42:24 UTC 2021


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun Nov  7 21:27:13 2021 -0800| [1fbfe8690cb9c55c86f7d4e328e4b9aa07e2f620] | committer: Nicolas Pomepuy

Show messages in the subtitle if seek fails

> https://code.videolan.org/videolan/vlc-android/commit/1fbfe8690cb9c55c86f7d4e328e4b9aa07e2f620
---

 .../src/org/videolan/vlc/MediaSessionCallback.kt          | 15 +++++++++++++--
 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt   | 10 +++++++++-
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 709ffa572..d1e17546e 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -228,6 +228,11 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
         }
     }
 
+    private fun checkforSeekFailure(forward: Boolean) {
+        if (playbackService.playlistManager.player.lastPosition == 0.0f && (forward || playbackService.getTime() > 0))
+            playbackService.displayPlaybackMessage(R.string.unseekable_stream)
+    }
+
     override fun onPlayFromUri(uri: Uri?, extras: Bundle?) = playbackService.loadUri(uri)
 
     override fun onPlayFromSearch(query: String?, extras: Bundle?) {
@@ -277,9 +282,15 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
 
     override fun onSeekTo(pos: Long) = playbackService.seek(if (pos < 0) playbackService.getTime() + pos else pos, fromUser = true)
 
-    override fun onFastForward() = playbackService.seek((playbackService.getTime() + TEN_SECONDS).coerceAtMost(playbackService.length), fromUser = true)
+    override fun onFastForward() {
+        playbackService.seek((playbackService.getTime() + TEN_SECONDS).coerceAtMost(playbackService.length), fromUser = true)
+        checkforSeekFailure(forward = true)
+    }
 
-    override fun onRewind() = playbackService.seek((playbackService.getTime() - TEN_SECONDS).coerceAtLeast(0), fromUser = true)
+    override fun onRewind() {
+        playbackService.seek((playbackService.getTime() - TEN_SECONDS).coerceAtLeast(0), fromUser = true)
+        checkforSeekFailure(forward = false)
+    }
 
     override fun onSkipToQueueItem(id: Long) = playbackService.playIndexOrLoadLastPlaylist(id.toInt())
 }
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index e10450622..cc6c50f1b 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -103,6 +103,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
     private lateinit var artworkMap: MutableMap<String, Uri>
 
     private val callbacks = mutableListOf<Callback>()
+    private val subtitleMessage = ArrayDeque<String>(1)
     private lateinit var cbActor : SendChannel<CbAction>
     private var detectHeadset = true
     private lateinit var wakeLock: PowerManager.WakeLock
@@ -915,6 +916,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         val length = length
         lastLength = length
         val chapterTitle = if (lastChaptersCount > 0) getChapters(-1)?.elementAtOrNull(lastChapter)?.name else null
+        val displayMsg = subtitleMessage.poll()
         val bob = withContext(Dispatchers.Default) {
             val carMode = AndroidDevices.isCarMode(ctx)
             val title = media.nowPlaying ?: media.title
@@ -931,7 +933,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
             }
             if (carMode) {
                 bob.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, chapterTitle ?: title)
-                bob.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, MediaUtils.getDisplaySubtitle(ctx, media, currentMediaPosition, mediaListSize))
+                bob.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, displayMsg ?: MediaUtils.getDisplaySubtitle(ctx, media, currentMediaPosition, mediaListSize))
                 bob.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, MediaUtils.getMediaAlbum(ctx, media))
             }
             if (Permissions.canReadStorage(this at PlaybackService) && coverOnLockscreen) {
@@ -1312,6 +1314,12 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         mediaSession.setPlaybackState(playbackState)
     }
 
+    fun displayPlaybackMessage(@StringRes resId: Int, vararg formatArgs: String) {
+        val ctx = this at PlaybackService
+        subtitleMessage.push(ctx.getString(resId, *formatArgs))
+        updateMetadata()
+    }
+
     @MainThread
     fun load(media: MediaWrapper) = load(listOf(media), 0)
 



More information about the Android mailing list