[Android] Restore load last playlist

Geoffrey Métais git at videolan.org
Fri Jun 1 11:12:08 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun  1 11:11:20 2018 +0200| [fe1a95e11da1d10774127298a7b49b0c118d075f] | committer: Geoffrey Métais

Restore load last playlist

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

 vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 767c84d2e..b3616b47b 100644
--- a/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -1,9 +1,11 @@
 package org.videolan.vlc
 
+import android.content.Intent
 import android.net.Uri
 import android.os.Bundle
 import android.support.v4.media.session.MediaSessionCompat
 import android.support.v4.media.session.PlaybackStateCompat
+import android.view.KeyEvent
 import kotlinx.coroutines.experimental.launch
 import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.media.MediaLibraryItem
@@ -15,6 +17,8 @@ import org.videolan.vlc.util.Constants
 import org.videolan.vlc.util.VoiceSearchParams
 import org.videolan.vlc.util.registerMedialibrary
 
+private const val TAG = "VLC/MediaSessionCallback"
+
 internal class MediaSessionCallback(private val playbackService: PlaybackService) : MediaSessionCompat.Callback() {
 
     override fun onPlay() {
@@ -22,6 +26,18 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
         else if (!AndroidDevices.isAndroidTv) PlaybackService.loadLastAudio(playbackService)
     }
 
+    override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
+        val keyEvent by lazy(LazyThreadSafetyMode.NONE) {  mediaButtonEvent.getParcelableExtra(Intent.EXTRA_KEY_EVENT) as KeyEvent? }
+        if (!playbackService.hasMedia() && keyEvent != null
+                && (keyEvent.keyCode == KeyEvent.KEYCODE_MEDIA_PLAY || keyEvent.keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)) {
+            return if (keyEvent.action == KeyEvent.ACTION_DOWN) {
+                PlaybackService.loadLastAudio(playbackService)
+                true
+            } else false
+        }
+        return super.onMediaButtonEvent(mediaButtonEvent)
+    }
+
     override fun onCustomAction(action: String?, extras: Bundle?) {
         when (action) {
             "shuffle" -> playbackService.shuffle()



More information about the Android mailing list