|
|
@ -413,29 +413,25 @@ private fun updateProgress() { |
|
|
PendingIntent.FLAG_UPDATE_CURRENT |
|
|
PendingIntent.FLAG_UPDATE_CURRENT |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
val builder = NotificationCompat.Builder(this, CHANNEL_ID) |
|
|
val builder = NotificationCompat.Builder(this, CHANNEL_ID) |
|
|
.setContentTitle(title) |
|
|
.setContentTitle(title) |
|
|
.setContentText(artist) |
|
|
.setContentText(artist) |
|
|
.setSmallIcon(android.R.drawable.ic_media_play) |
|
|
.setSmallIcon(R.drawable.ic_play) |
|
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) |
|
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) |
|
|
.setStyle( |
|
|
.setStyle( |
|
|
androidx.media.app.NotificationCompat.MediaStyle() |
|
|
androidx.media.app.NotificationCompat.MediaStyle() |
|
|
.setMediaSession(mediaSession.sessionToken) |
|
|
.setMediaSession(mediaSession.sessionToken) |
|
|
.setShowActionsInCompactView(0, 1, 2) |
|
|
.setShowActionsInCompactView(0, 1, 2) |
|
|
) |
|
|
) |
|
|
.addAction(android.R.drawable.ic_media_previous, "上一首", prevIntent) |
|
|
.addAction(R.drawable.ic_prev, "上一首", prevIntent) |
|
|
.addAction( |
|
|
.addAction( |
|
|
if (currentStatus) android.R.drawable.ic_media_pause else android.R.drawable.ic_media_play, |
|
|
if (currentStatus) R.drawable.ic_pause else R.drawable.ic_play, |
|
|
if (currentStatus) "暂停" else "播放", |
|
|
if (currentStatus) "暂停" else "播放", |
|
|
playPauseIntent |
|
|
playPauseIntent |
|
|
) |
|
|
) |
|
|
.addAction(android.R.drawable.ic_media_next, "下一首", nextIntent) |
|
|
.addAction(R.drawable.ic_next, "下一首", nextIntent) |
|
|
// 添加删除通知按钮 |
|
|
.setOngoing(false) |
|
|
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "删除", deletePendingIntent) |
|
|
|
|
|
.setOngoing(currentStatus) |
|
|
|
|
|
.setDeleteIntent(deletePendingIntent) // 设置通知被滑动删除时的行为 |
|
|
.setDeleteIntent(deletePendingIntent) // 设置通知被滑动删除时的行为 |
|
|
|
|
|
|
|
|
// 异步加载封面图 |
|
|
// 异步加载封面图 |
|
|
if (!coverUrl.isNullOrEmpty()) { |
|
|
if (!coverUrl.isNullOrEmpty()) { |
|
|
Thread { |
|
|
Thread { |
|
|
@ -644,6 +640,8 @@ private fun updateProgress() { |
|
|
if (player.isPlaying || currentStatus) { |
|
|
if (player.isPlaying || currentStatus) { |
|
|
player.seekTo(positionMs) |
|
|
player.seekTo(positionMs) |
|
|
Log.i(TAG, "跳转到位置: ${positionMs}ms") |
|
|
Log.i(TAG, "跳转到位置: ${positionMs}ms") |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} catch (e: Exception) { |
|
|
} catch (e: Exception) { |
|
|
Log.e(TAG, "跳转失败: ${e.message}") |
|
|
Log.e(TAG, "跳转失败: ${e.message}") |
|
|
|