From 1b939d5dadaa86abde2475f66f7bcec44de38995 Mon Sep 17 00:00:00 2001 From: Oleksandr Kharchenko Date: Mon, 19 Aug 2024 15:56:20 +0300 Subject: [PATCH 1/3] [ZEUS-4787] Fixed background service issue when switching video url --- .../bitmovin/BitmovinVideoPlayerPlugin.kt | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt b/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt index 4929ec2..0f54b68 100644 --- a/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt +++ b/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt @@ -2,6 +2,7 @@ package com.streamamg.player.plugin.bitmovin import android.Manifest import android.app.Activity +import android.app.ActivityManager import android.content.ComponentName import android.content.Context import android.content.ContextWrapper @@ -82,17 +83,12 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin { AndroidView( modifier = Modifier.fillMaxSize(), factory = { context -> - if (!playerConfig.playbackConfig.backgroundPlaybackEnabled) { // Init the Player without the Background service - if (playerBind == null) { - val playerConfig = - PlayerConfig(key = PlaybackSDKManager.bitmovinLicense) - playerBind = Player(context, playerConfig) - } - if (playerView == null) { - playerView = PlayerView(context, playerBind) - } + val playerConfig = + PlayerConfig(key = PlaybackSDKManager.bitmovinLicense) + playerBind = Player(context, playerConfig) + playerView = PlayerView(context, playerBind) initializePlayer(lastHlsUrl.value) } else { // Init the Player with the Background service later in the BackgroundPlaybackService @@ -223,11 +219,24 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin { } } + fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean { + val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + val services: List = activityManager.getRunningServices(Int.MAX_VALUE) + + for (runningServiceInfo in services) { + if (runningServiceInfo.service.getClassName().equals(serviceClass.name)) { + return true + } + } + return false + } + private fun bindAndStartBackgroundService(context: Context) { val intent = Intent(context, BackgroundPlaybackService::class.java) try { - if (BackgroundPlaybackService.isRunning) { + if (isServiceRunning(context, BackgroundPlaybackService::class.java)) { + context.unbindService(mConnection) context.stopService(intent) } context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE) @@ -238,7 +247,9 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin { } private fun unbindAndStopBackgroundService(context: Context) { - if (!isServiceBound) return + if (!isServiceBound) { + return + } val intent = Intent(context, BackgroundPlaybackService::class.java) From e68114751a8a9ab4bb82e29258c5617e416aabd6 Mon Sep 17 00:00:00 2001 From: Oleksandr Kharchenko Date: Mon, 19 Aug 2024 16:00:45 +0300 Subject: [PATCH 2/3] [ZEUS-4787] small code updates --- .../player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt b/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt index 0f54b68..883d2fc 100644 --- a/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt +++ b/playback-sdk-android/src/main/java/com/streamamg/player/plugin/bitmovin/BitmovinVideoPlayerPlugin.kt @@ -247,9 +247,7 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin { } private fun unbindAndStopBackgroundService(context: Context) { - if (!isServiceBound) { - return - } + if (!isServiceBound) return val intent = Intent(context, BackgroundPlaybackService::class.java) From 0ede191d957710413199fc6aade734d94ef1773e Mon Sep 17 00:00:00 2001 From: "Artem Y." Date: Tue, 20 Aug 2024 11:49:07 +0300 Subject: [PATCH 3/3] [ZEUS-4787] Bump sdk version to 1.0.4 --- playback-sdk-android/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playback-sdk-android/build.gradle.kts b/playback-sdk-android/build.gradle.kts index 383013d..aec4178 100644 --- a/playback-sdk-android/build.gradle.kts +++ b/playback-sdk-android/build.gradle.kts @@ -24,7 +24,7 @@ plugins { } group = "com.streamamg" -version = "1.0.2" +version = "1.0.4" subprojects { apply(plugin = "org.jetbrains.dokka")