[Android] Send a remote access ws message when waiting for the resume confirmation
Nicolas Pomepuy
git at videolan.org
Mon Nov 18 13:23:22 UTC 2024
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Nov 15 09:43:21 2024 +0100| [d8d2c136348487f08ab79ce67727009239fbcf49] | committer: Duncan McNamara
Send a remote access ws message when waiting for the resume confirmation
> https://code.videolan.org/videolan/vlc-android/commit/d8d2c136348487f08ab79ce67727009239fbcf49
---
.../vlc-android/src/org/videolan/vlc/PlaybackService.kt | 1 +
.../org/videolan/vlc/gui/AudioPlayerContainerActivity.kt | 4 ++++
.../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt | 4 ++++
.../java/org/videolan/vlc/webserver/RemoteAccessServer.kt | 13 ++++++++++++-
.../java/org/videolan/vlc/webserver/TranslationMapping.kt | 3 +++
5 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index df24f2b28d..4e1cb72166 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1942,6 +1942,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner, CoroutineSc
val restartPlayer = LiveEvent<Boolean>()
val headSetDetection = LiveEvent<Boolean>()
val equalizer = LiveEvent<MediaPlayer.Equalizer?>()
+ val waitConfirmation = LiveEvent<String?>()
private const val SHOW_TOAST = "show_toast"
private const val END_MEDIASESSION = "end_mediasession"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
index 1734905db8..b483824d5d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
@@ -259,6 +259,7 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener, Sched
private fun showConfirmResumeDialog(confirmation: WaitConfirmation) {
PlaybackService.instance?.pause()
+ PlaybackService.waitConfirmation.postValue(confirmation.title)
val inflater = this.layoutInflater
val dialogView = inflater.inflate(R.layout.dialog_video_resume, null)
val resumeAllCheck = dialogView.findViewById<CheckBox>(R.id.video_resume_checkbox)
@@ -274,6 +275,9 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener, Sched
if (resumeAllCheck.isChecked) PlaybackService.instance?.playlistManager?.audioResumeStatus = ResumeStatus.NEVER
lifecycleScope.launch { PlaybackService.instance?.playlistManager?.playIndex(confirmation.index, confirmation.flags, forceRestart = true) }
}
+ .setOnDismissListener {
+ PlaybackService.waitConfirmation.postValue(null)
+ }
.create().apply {
setCancelable(true)
setOnCancelListener {
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 9b5446e647..18644c4301 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
@@ -2330,6 +2330,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
return
}
service?.pause()
+ PlaybackService.waitConfirmation.postValue(confirmation.title)
val inflater = this.layoutInflater
val dialogView = inflater.inflate(R.layout.dialog_video_resume, null)
val resumeAllCheck = dialogView.findViewById<CheckBox>(R.id.video_resume_checkbox)
@@ -2344,6 +2345,9 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
if (resumeAllCheck.isChecked) service?.playlistManager?.videoResumeStatus = ResumeStatus.NEVER
lifecycleScope.launch { service?.playlistManager?.playIndex(confirmation.index, confirmation.flags, forceRestart = true) }
}
+ .setOnDismissListener {
+ PlaybackService.waitConfirmation.postValue(null)
+ }
.create().apply {
setCancelable(false)
setOnKeyListener { dialog, keyCode, _ ->
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 917da090cf..e355d416c7 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
@@ -32,7 +32,6 @@ import android.net.Uri
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
-import com.google.gson.Gson
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
@@ -165,6 +164,15 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
}
}
+ /**
+ * Observes the resume confirmation and display a dialog on the website
+ */
+ private val confirmationObserver = androidx.lifecycle.Observer<String?> { mediaTitle ->
+ AppScope.launch {
+ RemoteAccessWebSockets.sendToAll(ResumeConfirmationNeeded(mediaTitle, mediaTitle == null))
+ }
+ }
+
private val scope =
CoroutineScope(SupervisorJob() + Dispatchers.IO + CoroutineExceptionHandler { _, throwable ->
Log.e(TAG, throwable.message, throwable)
@@ -497,12 +505,14 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
AppScope.launch(Dispatchers.Main) {
PlaylistManager.showAudioPlayer.observeForever(miniPlayerObserver)
DialogActivity.loginDialogShown.observeForever(loginObserver)
+ PlaybackService.waitConfirmation.observeForever(confirmationObserver)
}
}
environment.monitor.subscribe(ApplicationStopped) {
AppScope.launch(Dispatchers.Main) {
PlaylistManager.showAudioPlayer.removeObserver(miniPlayerObserver)
DialogActivity.loginDialogShown.removeObserver(loginObserver)
+ PlaybackService.waitConfirmation.removeObserver(confirmationObserver)
}
_serverStatus.postValue(ServerStatus.STOPPED)
}
@@ -763,6 +773,7 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
data class Volume(val volume: Int) : WSMessage("volume")
data class PlayerStatus(val playing: Boolean) : WSMessage("player-status")
data class LoginNeeded(val dialogOpened: Boolean) : WSMessage("login-needed")
+ data class ResumeConfirmationNeeded(val mediaTitle: String?, val consumed:Boolean) : WSMessage("resume-confirmation")
data class MLRefreshNeeded(val refreshNeeded: Boolean = true) : WSMessage("ml-refresh-needed")
data class BrowserDescription(val path: String, val description:String) : WSMessage("browser-description")
data class PlaybackControlForbidden(val forbidden: Boolean = true): WSMessage("playback-control-forbidden")
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 66e322ab1f..cf017ed603 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
@@ -140,5 +140,8 @@ object TranslationMapping {
MINUTES(R.string.talkback_minutes),
VIDEO_PLAYER_REMOTE(R.string.video_player_remote),
REMOTE_KEYBOARD_NAVIGATION(R.string.remote_keyboard_navigation),
+ RESUME(R.string.resume),
+ CONFIRM_RESUME(R.string.confirm_resume),
+ NO(R.string.no)
}
}
\ No newline at end of file
More information about the Android
mailing list