Skip to content

Commit

Permalink
[ZEUS-4787] Fixed issue for the related videos
Browse files Browse the repository at this point in the history
  • Loading branch information
KharchenkoAlex committed Aug 19, 2024
1 parent 0cd28ed commit d5c750b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -10,6 +11,7 @@ import android.content.ServiceConnection
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.IBinder
import android.util.Log
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -82,17 +84,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)
}
initializePlayer(lastHlsUrl.value)
} else {
// Init the Player with the Background service later in the BackgroundPlaybackService
Expand Down Expand Up @@ -223,11 +220,24 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
}
}

fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean {
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val services: List<ActivityManager.RunningServiceInfo> = 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)
Expand All @@ -238,7 +248,9 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
}

private fun unbindAndStopBackgroundService(context: Context) {
if (!isServiceBound) return
if (!isServiceBound) {
return
}

val intent = Intent(context, BackgroundPlaybackService::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
import com.bitmovin.player.api.Player
import com.bitmovin.player.api.PlayerConfig
Expand Down

0 comments on commit d5c750b

Please sign in to comment.