diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 33f9d205..bb141b3b 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -975,7 +975,11 @@ public class ReactExoplayerView extends FrameLayout implements Intent intent = new Intent(themedReactContext, VideoPlaybackService.class); intent.setAction(MediaSessionService.SERVICE_INTERFACE); - themedReactContext.startService(intent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + themedReactContext.startForegroundService(intent); + } else { + themedReactContext.startService(intent); + } int flags; if (Build.VERSION.SDK_INT >= 29) { diff --git a/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt b/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt index 084099a2..b60df6fa 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt +++ b/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt @@ -63,6 +63,7 @@ class VideoPlaybackService : MediaSessionService() { mediaSessionsList[player] = mediaSession addSession(mediaSession) + startForeground(mediaSession.player.hashCode(), buildNotification(mediaSession)) } fun unregisterPlayer(player: ExoPlayer) { @@ -95,6 +96,10 @@ class VideoPlaybackService : MediaSessionService() { override fun onDestroy() { cleanup() + val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + notificationManager.deleteNotificationChannel(NOTIFICATION_CHANEL_ID) + } super.onDestroy() } @@ -209,9 +214,6 @@ class VideoPlaybackService : MediaSessionService() { private fun hideAllNotifications() { val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.cancelAll() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - notificationManager.deleteNotificationChannel(NOTIFICATION_CHANEL_ID) - } } private fun cleanup() {