From e1d3b95f73c2aba6e790813a1ea1e56c9ad31956 Mon Sep 17 00:00:00 2001 From: Koen <koen@pop-os.localdomain> Date: Tue, 7 Nov 2023 13:35:13 +0100 Subject: [PATCH] Fixed crash on Android 9 when playing a video. --- .../futo/platformplayer/services/MediaPlaybackService.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/futo/platformplayer/services/MediaPlaybackService.kt b/app/src/main/java/com/futo/platformplayer/services/MediaPlaybackService.kt index e383b3a1..7f076304 100644 --- a/app/src/main/java/com/futo/platformplayer/services/MediaPlaybackService.kt +++ b/app/src/main/java/com/futo/platformplayer/services/MediaPlaybackService.kt @@ -10,6 +10,7 @@ import android.media.AudioFocusRequest import android.media.AudioManager import android.media.AudioManager.OnAudioFocusChangeListener import android.media.MediaMetadata +import android.os.Build import android.os.IBinder import android.os.SystemClock import android.support.v4.media.MediaMetadataCompat @@ -278,7 +279,13 @@ class MediaPlaybackService : Service() { Logger.i(TAG, "Updating notification bitmap=${if (bitmap != null) "yes" else "no."} channelId=${channel.id} icon=${icon} video=${video?.name ?: ""} playWhenReady=${playWhenReady} session.sessionToken=${session.sessionToken}"); - startForeground(MEDIA_NOTIF_ID, notif, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + // For API 29 and above + startForeground(MEDIA_NOTIF_ID, notif, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); + } else { + // For API 28 and below + startForeground(MEDIA_NOTIF_ID, notif); + } _notif_last_bitmap = bitmap; } -- GitLab