[Android] Remote access: add chapter API and media info strings

Nicolas Pomepuy git at videolan.org
Mon Sep 9 15:14:15 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Aug 12 11:23:31 2024 +0200| [e21e57d3a28abb227542416fbf61ef47e672e7cf] | committer: Duncan McNamara

Remote access: add chapter API and media info strings

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

 application/resources/src/main/res/values/strings.xml                | 1 +
 .../src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt   | 5 +++--
 .../src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt   | 4 ++++
 .../org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt  | 5 +++++
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 133370a883..c0dc94d07a 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -601,6 +601,7 @@
     <string name="search_global">Search in all media library</string>
     <string name="playlist_save">Save Playlist</string>
     <string name="playlist_name_hint">Playlist name</string>
+    <string name="chapters">Chapters</string>
     <string name="go_to_chapter">Go to chapter…</string>
     <string name="current_chapter">Chapter: %s</string>
     <string name="confirm_resume">Resume from last position?</string>
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt
index 4b104a7103..c69d769063 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt
@@ -584,9 +584,10 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
         service?.let { service ->
             service.currentMediaWrapper?.let { media ->
                 val bookmarks = withContext(Dispatchers.IO) { media.bookmarks ?: arrayOf() }
+                val chapters = withContext(Dispatchers.IO) { service.getChapters(-1) ?: arrayOf() }
                 val nowPlaying = NowPlaying(media.title ?: "", media.artist
                         ?: "", service.isPlaying, service.getTime(), service.length, media.id, media.artworkURL
-                        ?: "", media.uri.toString(), getVolume(), service.isShuffling, service.repeatType, bookmarks = bookmarks.map { WSBookmark(it.title, it.time) })
+                        ?: "", media.uri.toString(), getVolume(), service.isShuffling, service.repeatType, bookmarks = bookmarks.map { WSBookmark(it.title, it.time) }, chapters = chapters.map { WSBookmark(it.name, it.duration) })
                 return nowPlaying
 
             }
@@ -739,7 +740,7 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
 
     abstract class WSMessage(val type: String)
     data class NowPlaying(val title: String, val artist: String, val playing: Boolean, val progress: Long, val duration: Long, val id: Long, val artworkURL: String, val uri: String, val volume: Int, val shuffle: Boolean, val repeat: Int, val shouldShow: Boolean = PlaylistManager.playingState.value
-            ?: false, val bookmarks:List<WSBookmark> = listOf()) : WSMessage("now-playing")
+            ?: false, val bookmarks:List<WSBookmark> = listOf(), val chapters:List<WSBookmark> = listOf()) : WSMessage("now-playing")
 
     data class WSBookmark(val title: String, val time: Long)
 
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt
index 309840b4e3..57565070c9 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/TranslationMapping.kt
@@ -125,5 +125,9 @@ object TranslationMapping {
         REMOTE_ACCESS_VERSION(R.string.remote_access_version),
         REMOTE_ACCESS_HASH(R.string.build_remote_access_revision),
         LIBRARIES(R.string.libraries),
+        SLEEP_TIMER(R.string.sleep_title),
+        PLAYBACK_SPEED(R.string.playback_speed),
+        CHAPTERS(R.string.chapters),
+        BOOKMARKS(R.string.bookmarks),
     }
 }
\ No newline at end of file
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
index 5a57c9232d..dd9b2dd339 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
@@ -170,6 +170,11 @@ object RemoteAccessWebSockets {
                 } else return false
             }
 
+                        "play-chapter" -> {
+                            incomingMessage.id?.let { id ->
+                                if (playbackControlAllowedOrSend(settings)) service?.chapterIdx = id
+                            }
+                        }
             "play-media" -> {
                 if (playbackControlAllowedOrSend(settings)) service?.playIndex(incomingMessage.id!!) else return false
 



More information about the Android mailing list