diff --git a/android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt index f298b42a..145f455b 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt @@ -4,7 +4,6 @@ import android.util.Log import com.bitmovin.player.api.Player import com.bitmovin.player.api.source.Source import com.bitmovin.player.reactnative.extensions.drmModule -import com.bitmovin.player.reactnative.extensions.mediaSessionModule import com.bitmovin.player.reactnative.extensions.networkModule import com.bitmovin.player.reactnative.extensions.offlineModule import com.bitmovin.player.reactnative.extensions.playerModule @@ -59,9 +58,6 @@ abstract class BitmovinBaseModule( protected val RejectPromiseOnExceptionBlock.networkModule: NetworkModule get() = context.networkModule ?: throw IllegalStateException("NetworkModule not found") - protected val RejectPromiseOnExceptionBlock.mediaSessionModule: MediaSessionModule - get() = context.mediaSessionModule ?: throw IllegalStateException("MediaSessionModule not found") - fun RejectPromiseOnExceptionBlock.getPlayer( nativeId: NativeId, playerModule: PlayerModule = this.playerModule, diff --git a/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionConnectionManager.kt similarity index 85% rename from android/src/main/java/com/bitmovin/player/reactnative/MediaSessionModule.kt rename to android/src/main/java/com/bitmovin/player/reactnative/MediaSessionConnectionManager.kt index f2cd9670..673183b0 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionConnectionManager.kt @@ -10,15 +10,10 @@ import com.bitmovin.player.api.Player import com.bitmovin.player.reactnative.extensions.playerModule import com.bitmovin.player.reactnative.services.MediaSessionPlaybackService import com.facebook.react.bridge.* -import com.facebook.react.module.annotations.ReactModule import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow -private const val MODULE_NAME = "MediaSessionModule" -@ReactModule(name = MODULE_NAME) -class MediaSessionModule(context: ReactApplicationContext) : BitmovinBaseModule(context) { - override fun getName() = MODULE_NAME - +class MediaSessionConnectionManager(val context: ReactApplicationContext) { private var isServiceStarted = false private lateinit var playerId: NativeId @@ -39,7 +34,7 @@ class MediaSessionModule(context: ReactApplicationContext) : BitmovinBaseModule( } fun setupMediaSession(playerId: NativeId) { - this@MediaSessionModule.playerId = playerId + this@MediaSessionConnectionManager.playerId = playerId val intent = Intent(context, MediaSessionPlaybackService::class.java) intent.action = Intent.ACTION_MEDIA_BUTTON diff --git a/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt index f1733a53..cbabe57b 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt @@ -26,6 +26,8 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex */ private val players: Registry = mutableMapOf() + var mediaSessionConnectionManager: MediaSessionConnectionManager? = null + /** * JS exported module name. */ @@ -93,9 +95,9 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex } if (playerConfig.lockScreenControlConfig.isEnabled) { + mediaSessionConnectionManager = MediaSessionConnectionManager(context) promise.unit.resolveOnUiThread { - mediaSessionModule - .setupMediaSession(nativeId) + mediaSessionConnectionManager?.setupMediaSession(nativeId) } } } @@ -222,6 +224,7 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex promise.unit.resolveOnUiThreadWithPlayer(nativeId) { destroy() players.remove(nativeId) + mediaSessionConnectionManager = null } } diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt index d2e2c14d..62da2df4 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt @@ -17,7 +17,7 @@ import com.bitmovin.player.api.ui.PlayerViewConfig import com.bitmovin.player.api.ui.StyleConfig import com.bitmovin.player.reactnative.converter.lockScreenControlConfig import com.bitmovin.player.reactnative.converter.toJson -import com.bitmovin.player.reactnative.extensions.mediaSessionModule +import com.bitmovin.player.reactnative.extensions.playerModule import com.facebook.react.ReactActivity import com.facebook.react.bridge.* import com.facebook.react.uimanager.events.RCTEventEmitter @@ -111,9 +111,9 @@ class RNPlayerView( private var playerEventRelay: EventRelay private var mediaSessionServicePlayer: Player? - get() = context.mediaSessionModule?.serviceBinder?.value?.player + get() = context.playerModule?.mediaSessionConnectionManager?.serviceBinder?.value?.player set(value) { - context.mediaSessionModule?.serviceBinder?.value?.player = value + context.playerModule?.mediaSessionConnectionManager?.serviceBinder?.value?.player = value } private val activityLifecycleObserver = object : DefaultLifecycleObserver { diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt index f74b1f3f..807f6f54 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt @@ -30,7 +30,6 @@ class RNPlayerViewPackage : ReactPackage { BitmovinCastManagerModule(reactContext), BufferModule(reactContext), NetworkModule(reactContext), - MediaSessionModule(reactContext), ) } diff --git a/android/src/main/java/com/bitmovin/player/reactnative/extensions/ReactContextExtension.kt b/android/src/main/java/com/bitmovin/player/reactnative/extensions/ReactContextExtension.kt index 31be9a22..64090363 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/extensions/ReactContextExtension.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/extensions/ReactContextExtension.kt @@ -1,7 +1,6 @@ package com.bitmovin.player.reactnative.extensions import com.bitmovin.player.reactnative.DrmModule -import com.bitmovin.player.reactnative.MediaSessionModule import com.bitmovin.player.reactnative.NetworkModule import com.bitmovin.player.reactnative.OfflineModule import com.bitmovin.player.reactnative.PlayerModule @@ -21,4 +20,3 @@ val ReactApplicationContext.uiManagerModule get() = getModule() val ReactApplicationContext.drmModule get() = getModule() val ReactApplicationContext.customMessageHandlerModule get() = getModule() val ReactApplicationContext.networkModule get() = getModule() -val ReactApplicationContext.mediaSessionModule get() = getModule()