[Android] Remote access: add the playback speed API
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 14:52:11 2024 +0200| [57d4f17de0eaa19ef3a3a4698ef2428ece71daf6] | committer: Duncan McNamara
Remote access: add the playback speed API
> https://code.videolan.org/videolan/vlc-android/commit/57d4f17de0eaa19ef3a3a4698ef2428ece71daf6
---
.../main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt | 3 ++-
.../main/java/org/videolan/vlc/webserver/RemoteAccessServer.kt | 5 +++--
.../videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt | 8 ++++++--
.../org/videolan/vlc/webserver/websockets/WSIncomingMessage.kt | 1 +
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
index c832603877..f6dfabf4c1 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
@@ -467,8 +467,9 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
get("/playback-event") {
call.request.queryParameters["message"]?.let { message ->
val id = call.request.queryParameters["id"]?.toInt()
+ val floatValue = call.request.queryParameters["floatValue"]?.toFloat()
val authTicket = call.request.queryParameters["authTicket"]
- if (!RemoteAccessWebSockets.manageIncomingMessages(WSIncomingMessage(message, id, authTicket), settings, RemoteAccessServer.getInstance(appContext).service, appContext)) {
+ if (!RemoteAccessWebSockets.manageIncomingMessages(WSIncomingMessage(message, id, floatValue, authTicket = authTicket), settings, RemoteAccessServer.getInstance(appContext).service, appContext)) {
call.respond(HttpStatusCode.Forbidden)
return at get
}
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 c69d769063..036bd388ce 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
@@ -585,9 +585,10 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
service.currentMediaWrapper?.let { media ->
val bookmarks = withContext(Dispatchers.IO) { media.bookmarks ?: arrayOf() }
val chapters = withContext(Dispatchers.IO) { service.getChapters(-1) ?: arrayOf() }
+ val speed = String.format(Locale.US, "%.2f", service.speed).toFloat()
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) }, chapters = chapters.map { WSBookmark(it.name, it.duration) })
+ ?: "", media.uri.toString(), getVolume(), speed, 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
+ 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 speed: Float, val shuffle: Boolean, val repeat: Int, val shouldShow: Boolean = PlaylistManager.playingState.value
?: 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/websockets/RemoteAccessWebSockets.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
index dd9b2dd339..b3a30f1fa2 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
@@ -66,8 +66,7 @@ object RemoteAccessWebSockets {
val incomingMessage = gson.fromJson(message, WSIncomingMessage::class.java)
if (BuildConfig.DEBUG) Log.i(TAG, "Received: $message")
if (!BuildConfig.VLC_REMOTE_ACCESS_DEBUG && !verifyWebsocketAuth(incomingMessage)) {
- val gson = Gson()
- send(Frame.Text(gson.toJson(RemoteAccessServer.WebSocketAuthorization("forbidden", initialMessage = message))))
+ send(Frame.Text(Gson().toJson(RemoteAccessServer.WebSocketAuthorization("forbidden", initialMessage = message))))
return at webSocket
}
val service = RemoteAccessServer.getInstance(context).service
@@ -175,6 +174,11 @@ object RemoteAccessWebSockets {
if (playbackControlAllowedOrSend(settings)) service?.chapterIdx = id
}
}
+ "speed" -> {
+ incomingMessage.floatValue?.let { speed ->
+ if (playbackControlAllowedOrSend(settings)) service?.setRate(speed, true)
+ }
+ }
"play-media" -> {
if (playbackControlAllowedOrSend(settings)) service?.playIndex(incomingMessage.id!!) else return false
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/WSIncomingMessage.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/WSIncomingMessage.kt
index 013b86b30a..2b79e09bb5 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/WSIncomingMessage.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/WSIncomingMessage.kt
@@ -27,5 +27,6 @@ package org.videolan.vlc.webserver.websockets
data class WSIncomingMessage(
val message: String,
val id: Int?,
+ val floatValue: Float? = null,
val authTicket: String? = null
)
\ No newline at end of file
More information about the Android
mailing list