Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.0.4 #27

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading