[Android] Restart player properly
Nicolas Pomepuy
git at videolan.org
Thu Jun 11 11:38:07 CEST 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Jun 5 13:44:55 2020 +0200| [4d14ea8661415c46771dae2fa4549576e08456ed] | committer: Nicolas Pomepuy
Restart player properly
Fixes #409
> https://code.videolan.org/videolan/vlc-android/commit/4d14ea8661415c46771dae2fa4549576e08456ed
---
application/vlc-android/src/org/videolan/vlc/PlaybackService.kt | 2 +-
.../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt | 7 +++++++
2 files changed, 8 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 7f5f094c2..5211b148b 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1028,7 +1028,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
@MainThread
fun removeCallback(cb: Callback) = cbActor.safeOffer(CbRemove(cb))
- fun restartMediaPlayer() = playlistManager.player.restart()
+ fun restartMediaPlayer() = playlistManager.restart()
fun saveMediaMeta() = playlistManager.saveMediaMeta()
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 00ac9abf6..ee34c2542 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -12,6 +12,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.actor
+import okhttp3.internal.waitMillis
import org.videolan.libvlc.FactoryManager
import org.videolan.libvlc.MediaPlayer
import org.videolan.libvlc.RendererItem
@@ -216,6 +217,12 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
launch { playIndex(currentIndex) }
}
+ fun restart() {
+ val isPlaying = player.isPlaying() && isAudioList()
+ stop()
+ if (isPlaying) PlaybackService.loadLastAudio(service)
+ }
+
fun stop(systemExit: Boolean = false, video: Boolean = false) {
clearABRepeat()
stopAfter = -1
More information about the Android
mailing list