[Android] Remote access: sleep timer

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug 13 10:24:10 2024 +0200| [4be6f021051597c2c46575e2d6a74c1a5a9271bd] | committer: Duncan McNamara

Remote access: sleep timer

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

 .../java/org/videolan/vlc/webserver/RemoteAccessRouting.kt     |  3 ++-
 .../vlc/webserver/websockets/RemoteAccessWebSockets.kt         | 10 ++++++++++
 .../org/videolan/vlc/webserver/websockets/WSIncomingMessage.kt |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)

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 f6dfabf4c1..755d8b2a90 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,9 +467,10 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
         get("/playback-event") {
             call.request.queryParameters["message"]?.let { message ->
                 val id = call.request.queryParameters["id"]?.toInt()
+                val longValue = call.request.queryParameters["longValue"]?.toLong()
                 val floatValue = call.request.queryParameters["floatValue"]?.toFloat()
                 val authTicket = call.request.queryParameters["authTicket"]
-                if (!RemoteAccessWebSockets.manageIncomingMessages(WSIncomingMessage(message, id, floatValue, authTicket = authTicket), settings, RemoteAccessServer.getInstance(appContext).service, appContext)) {
+                if (!RemoteAccessWebSockets.manageIncomingMessages(WSIncomingMessage(message, id, floatValue, longValue, 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/websockets/RemoteAccessWebSockets.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/websockets/RemoteAccessWebSockets.kt
index b3a30f1fa2..4278ef958b 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
@@ -44,6 +44,7 @@ import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.webserver.BuildConfig
 import org.videolan.vlc.webserver.RemoteAccessServer
 import org.videolan.vlc.webserver.ssl.SecretGenerator
+import java.util.Calendar
 
 object RemoteAccessWebSockets {
     val messageQueue: ArrayList<RemoteAccessServer.WSMessage> = arrayListOf()
@@ -179,6 +180,15 @@ object RemoteAccessWebSockets {
                                 if (playbackControlAllowedOrSend(settings)) service?.setRate(speed, true)
                             }
                         }
+                        "sleep-timer" -> {
+                            incomingMessage.longValue?.let { sleepTimerEnd ->
+                                val sleepTime = Calendar.getInstance()
+                                sleepTime.timeInMillis = sleepTime.timeInMillis + sleepTimerEnd
+                                sleepTime.set(Calendar.SECOND, 0)
+                                service?.setSleepTimer(sleepTime)
+                                if (playbackControlAllowedOrSend(settings)) service?.sleepTimerInterval = sleepTimerEnd
+                            }
+                        }
             "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 2b79e09bb5..0bb73d67da 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
@@ -28,5 +28,6 @@ data class WSIncomingMessage(
             val message: String,
             val id: Int?,
             val floatValue: Float? = null,
+            val longValue: Long? = null,
             val authTicket: String? = null
 )
\ No newline at end of file



More information about the Android mailing list