Skip to content

Commit

Permalink
Merge pull request #27 from StreamAMG/release/1.0.4
Browse files Browse the repository at this point in the history
Release/1.0.4
  • Loading branch information
artem-y-pamediagroup authored Aug 20, 2024
2 parents bf5a802 + b10e7be commit e6139db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion playback-sdk-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
}

group = "com.streamamg"
version = "1.0.2"
version = "1.0.4"

subprojects {
apply(plugin = "org.jetbrains.dokka")
Expand Down
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 Down Expand Up @@ -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
Expand Down Expand Up @@ -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.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 Down

0 comments on commit e6139db

Please sign in to comment.