diff --git a/local_plugins/music_service/android/src/main/AndroidManifest.xml b/local_plugins/music_service/android/src/main/AndroidManifest.xml
index 0b1f1fde9..3bb95fe3e 100644
--- a/local_plugins/music_service/android/src/main/AndroidManifest.xml
+++ b/local_plugins/music_service/android/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
+
= Build.VERSION_CODES.M) {
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
+ } else {
+ PendingIntent.FLAG_UPDATE_CURRENT
+ }
+ return PendingIntent.getService(this, action.toInt(), intent, flags)
+ }
+ // 转换 PlaybackStateCompat.ACTION 到 KeyEvent
+ fun Long.toKeyCode(): Int = when (this) {
+ PlaybackStateCompat.ACTION_PLAY -> KeyEvent.KEYCODE_MEDIA_PLAY
+ PlaybackStateCompat.ACTION_PAUSE -> KeyEvent.KEYCODE_MEDIA_PAUSE
+ PlaybackStateCompat.ACTION_SKIP_TO_NEXT -> KeyEvent.KEYCODE_MEDIA_NEXT
+ PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS -> KeyEvent.KEYCODE_MEDIA_PREVIOUS
+ else -> KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
+ }
/**
* 设置播放状态
*/
@@ -242,7 +261,7 @@ class MusicService : MediaBrowserServiceCompat() {
}
prepareAsync()
}
- setPlaybackState(PlaybackStateCompat.STATE_PAUSED);
+ setPlaybackState(PlaybackStateCompat.STATE_PLAYING);
}
private fun pause() {
@@ -259,7 +278,7 @@ class MusicService : MediaBrowserServiceCompat() {
val artist = song["artist"] ?: "未知歌手"
val coverUrl = song["coverUrl"]
updateNotification(title,artist,coverUrl)
- setPlaybackState(PlaybackStateCompat.STATE_PLAYING);
+ setPlaybackState(PlaybackStateCompat.STATE_PAUSED);
Log.i(TAG, "已暂停")
}
@@ -279,7 +298,7 @@ class MusicService : MediaBrowserServiceCompat() {
val artist = song["artist"] ?: "未知歌手"
val coverUrl = song["coverUrl"]
updateNotification(title,artist,coverUrl)
- setPlaybackState(PlaybackStateCompat.STATE_PAUSED);
+ setPlaybackState(PlaybackStateCompat.STATE_PLAYING);
// Log.i(TAG, "继续播放")
}
}
diff --git a/local_plugins/music_service/android/src/main/kotlin/com/yunqiinnovation/music_service/MusicServiceStarter.kt b/local_plugins/music_service/android/src/main/kotlin/com/yunqiinnovation/music_service/MusicServiceStarter.kt
index 4c743d18a..b46fa3230 100644
--- a/local_plugins/music_service/android/src/main/kotlin/com/yunqiinnovation/music_service/MusicServiceStarter.kt
+++ b/local_plugins/music_service/android/src/main/kotlin/com/yunqiinnovation/music_service/MusicServiceStarter.kt
@@ -2,8 +2,10 @@ package com.yunqiinnovation.music_service
import android.content.Context
import android.content.Intent
+import android.os.Build
import android.util.Log
import androidx.core.content.ContextCompat
+import java.util.jar.Manifest
//@Parcelize
//data class Song(