[Android] Invoke playback service on the main thread
Robert Stone
git at videolan.org
Thu Nov 25 06:45:31 UTC 2021
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sat Nov 20 20:32:52 2021 -0800| [211b993e2a33df50b74cee5ea85589f9cbd3f89b] | committer: Nicolas Pomepuy
Invoke playback service on the main thread
> https://code.videolan.org/videolan/vlc-android/commit/211b993e2a33df50b74cee5ea85589f9cbd3f89b
---
.../vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt | 10 ++++++----
.../vlc-android/src/org/videolan/vlc/PlaybackService.kt | 5 ++++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 77fd0e4a0..bb432b090 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -283,10 +283,12 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
}
if (!isActive) return at launch
if (tracks.isNullOrEmpty() && !items.isNullOrEmpty()) tracks = items[0].tracks
- when {
- !tracks.isNullOrEmpty() -> loadMedia(tracks?.toList())
- playbackService.hasMedia() -> playbackService.play()
- else -> playbackService.displayPlaybackError(R.string.search_no_result)
+ playbackService.lifecycleScope.launch(Dispatchers.Main) {
+ when {
+ !tracks.isNullOrEmpty() -> loadMedia(tracks?.toList())
+ playbackService.hasMedia() -> playbackService.play()
+ else -> playbackService.displayPlaybackError(R.string.search_no_result)
+ }
}
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index c8822cf99..7aeb0cf16 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -246,6 +246,10 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
private var currentWidgetCover: String? = null
+ val speed: Float
+ @MainThread
+ get() = playlistManager.player.speed.value ?: 1.0F
+
val isPlaying: Boolean
@MainThread
get() = playlistManager.player.isPlaying()
@@ -1061,7 +1065,6 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
}
private fun addCustomSpeedActions(pscb: PlaybackStateCompat.Builder, showSpeedActions: Boolean = true) {
- val speed = playlistManager.player.speed.value ?: 1.0F
if (speed != 1.0F || showSpeedActions) {
val speedIcons = hashMapOf(
0.50f to R.drawable.ic_auto_speed_0_50,
More information about the Android
mailing list