Skip to content

Commit

Permalink
Merge pull request #24 from StreamAMG/release/1.0.3
Browse files Browse the repository at this point in the history
Release/1.0.3
  • Loading branch information
artem-y-pamediagroup authored Aug 16, 2024
2 parents e800dda + e72981b commit bf5a802
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 44 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Android Build and Test

on:
push:
branches: [ "main", "release/*"]
pull_request:
branches: [ "main", "release/*" ]

jobs:
build:
name: Gradle build and test
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Java JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
java-package: 'jdk'

- name: Setup Android SDK
uses: android-actions/setup-android@v2

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Clean build directory
run: ./gradlew clean

- name: Run unit tests
run: ./gradlew testDebugUnitTest --warning-mode=all --scan
4 changes: 3 additions & 1 deletion playback-sdk-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ android {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
languageVersion = JavaLanguageVersion.of(17)
}
}

Expand Down Expand Up @@ -163,4 +163,6 @@ dependencies {
implementation("com.bitmovin.player:player:3.61.0")
implementation("com.google.android.gms:play-services-cast-framework:21.4.0")
implementation("com.google.accompanist:accompanist-permissions:0.28.0")

testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0-RC")
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
private var playerConfig = VideoPlayerConfig()
private var playerBind: Player? = null
private val fullscreen = mutableStateOf(false)
private var isServiceBound = false

override fun setup(config: VideoPlayerConfig) {
playerConfig.playbackConfig.autoplayEnabled = config.playbackConfig.autoplayEnabled
Expand All @@ -72,7 +73,7 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
RequestMissingPermissions()
} else {
// Bind and start the Background service without permissions
backgroundService(true, LocalContext.current)
bindAndStartBackgroundService(LocalContext.current)
}
}

Expand Down Expand Up @@ -127,8 +128,7 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
}
override fun onDestroy(owner: LifecycleOwner) {
if (playerConfig.playbackConfig.backgroundPlaybackEnabled) {
// Stop and unbind the Background service
backgroundService(false, context)
unbindAndStopBackgroundService(context)
}
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
val context = LocalContext.current
val permissionState = rememberPermissionState(permission = Manifest.permission.POST_NOTIFICATIONS) { granted ->
if (granted) {
backgroundService(true, context)
bindAndStartBackgroundService(context)
}
}
if (!permissionState.status.isGranted) {
Expand All @@ -219,29 +219,43 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
block = { permissionState.launchPermissionRequest() }
)
} else {
// Bind and start the Background service
backgroundService(true, context)
bindAndStartBackgroundService(context)
}
}

private fun backgroundService(start: Boolean, context: Context) {
private fun bindAndStartBackgroundService(context: Context) {
val intent = Intent(context, BackgroundPlaybackService::class.java)
if (start) {

try {
if (BackgroundPlaybackService.isRunning) {
context.stopService(intent)
}
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE)
context.startService(intent)
} else {
context.stopService(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}

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

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

try {
context.unbindService(mConnection)
context.stopService(intent)
isServiceBound = false
} catch (e: Exception) {
e.printStackTrace()
}
}

/**
* Defines callbacks for service binding, passed to bindService()
*/
private val mConnection = object : ServiceConnection {

override fun onServiceConnected(className: ComponentName, service: IBinder) {
// We've bound to the Service, cast the IBinder and get the Player instance
val binder = service as BackgroundPlaybackService.BackgroundBinder
Expand All @@ -254,9 +268,11 @@ class BitmovinVideoPlayerPlugin : VideoPlayerPlugin {
playerView?.player = playerBind

initializePlayer(this@BitmovinVideoPlayerPlugin.hlsUrl)
isServiceBound = true
}

override fun onServiceDisconnected(arg0: ComponentName) {
isServiceBound = false
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package com.streamamg.playback_sdk_android_app

import androidx.compose.runtime.Composable
import com.streamamg.PlaybackSDKManager
import com.streamamg.SDKError
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Test
import java.net.URL

class PlaybackSDKManagerTests {

private lateinit var manager: PlaybackSDKManager
private val apiKey = "f3Beljhmlz2ea7M9TfErE6mKPsAcY3BrasMMEG24"
private val entryID = "0_k3mz0mf8"
private val apiKey = "EJEZPIezBkaf0EQ7ey5Iu2MDA2ARUkgc79eyDOnG"
private val entryID = "0_qt9cy11s"

val scope = TestScope()

@Before
fun setUp() {
Dispatchers.setMain(StandardTestDispatcher(scope.testScheduler))
manager = PlaybackSDKManager
}

Expand All @@ -27,41 +31,29 @@ class PlaybackSDKManagerTests {
}

@Test
fun testInitializeWithValidAPIKey() {
val completion: (String?, SDKError?) -> Unit = { _, _ -> }
runBlocking {
manager.initialize(apiKey) { license, error ->
assertNotNull(license)
assertNull(error)
}
fun testInitializeWithValidAPIKey() = runTest {
manager.initialize(apiKey, userAgent = "userAgent") { license, error ->
assertNotNull(license)
assertNull(error)
}
}

@Test
fun testLoadHLSStream() {
val completion: (URL?, SDKError?) -> Unit = { _, _ -> }
runBlocking {
manager.loadHLSStream(entryID, null, null) { hlsURL, error ->
assertNotNull(hlsURL)
assertNull(error)
}
fun testLoadHLSStream() = runTest {
manager.initialize(apiKey = apiKey, userAgent = "userAgent") { license, error ->
assertNotNull(license)
assertNull(error)
}
}

@Test
fun testInitializeWithEmptyAPIKey() {
val completion: (String?, SDKError?) -> Unit = { _, _ -> }
runBlocking {
manager.initialize("") { _, error ->
assertNull(error)
}
manager.loadHLSStream(entryID, null, "userAgent") { hlsURL, error ->
assertNotNull(hlsURL)
assertNull(error)
}
}

@Composable
@Test
fun testLoadPlayer() {
val player = manager.loadPlayer(entryID, "authToken", "userAgent") {}
assertNotNull(player)
fun testInitializeWithEmptyAPIKey() = runTest {
manager.initialize("", userAgent = "userAgent") { _, error ->
assertNotNull(error) // Expect an error with empty API key
}
}
}

0 comments on commit bf5a802

Please sign in to comment.