Skip to content

Commit

Permalink
Simplify LockScreenControlConfig serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
123mpozzi committed Oct 23, 2024
1 parent 40be6a7 commit e239fce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import com.bitmovin.player.api.Player
import com.bitmovin.player.api.PlayerConfig
import com.bitmovin.player.api.analytics.create
import com.bitmovin.player.api.event.PlayerEvent
import com.bitmovin.player.reactnative.converter.lockScreenControlConfig
import com.bitmovin.player.reactnative.converter.toAdItem
import com.bitmovin.player.reactnative.converter.toAnalyticsConfig
import com.bitmovin.player.reactnative.converter.toAnalyticsDefaultMetadata
import com.bitmovin.player.reactnative.converter.toJson
import com.bitmovin.player.reactnative.converter.toLockScreenControlConfig
import com.bitmovin.player.reactnative.converter.toPlayerConfig
import com.bitmovin.player.reactnative.extensions.mapToReactArray
import com.facebook.react.bridge.*
Expand All @@ -27,6 +27,7 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex
private val players: Registry<Player> = mutableMapOf()

var mediaSessionConnectionManager: MediaSessionConnectionManager? = null
var isMediaSessionPlaybackEnabled: Boolean = false

/**
* JS exported module name.
Expand Down Expand Up @@ -77,6 +78,8 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex
val playerConfig = playerConfigJson?.toPlayerConfig() ?: PlayerConfig()
val analyticsConfig = analyticsConfigJson?.toAnalyticsConfig()
val defaultMetadata = analyticsConfigJson?.getMap("defaultMetadata")?.toAnalyticsDefaultMetadata()
isMediaSessionPlaybackEnabled = playerConfigJson?.getMap("lockScreenControlConfig")
?.toLockScreenControlConfig()?.isEnabled ?: false

val networkConfig = networkNativeId?.let { networkModule.getConfig(it) }
if (networkConfig != null) {
Expand All @@ -94,7 +97,7 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex
)
}

if (playerConfig.lockScreenControlConfig.isEnabled) {
if (isMediaSessionPlaybackEnabled) {
mediaSessionConnectionManager = MediaSessionConnectionManager(context)
promise.unit.resolveOnUiThread {
mediaSessionConnectionManager?.setupMediaSession(nativeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class RNPlayerView(
}

override fun onStop(owner: LifecycleOwner) {
if (player?.config?.lockScreenControlConfig?.isEnabled == false) {
if (context.playerModule?.isMediaSessionPlaybackEnabled == false) {
mediaSessionServicePlayer = null
} else {
player = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ fun ReadableMap.toPlayerConfig(): PlayerConfig = PlayerConfig(key = getString("l
withMap("bufferConfig") { bufferConfig = it.toBufferConfig() }
withMap("liveConfig") { liveConfig = it.toLiveConfig() }
withMap("networkConfig") { networkConfig = it.toNetworkConfig() }
withMap("lockScreenControlConfig") { lockScreenControlConfig = it.toLockScreenControlConfig() }
}

/**
Expand Down Expand Up @@ -892,13 +891,6 @@ fun ReadableMap.toLockScreenControlConfig(): LockScreenControlConfig = LockScree
withBoolean("isEnabled") { isEnabled = it }
}

private val lockScreenConfigMap = mutableMapOf<PlayerConfig, LockScreenControlConfig>()
var PlayerConfig.lockScreenControlConfig: LockScreenControlConfig
get() = lockScreenConfigMap[this] ?: LockScreenControlConfig()
set(value) {
lockScreenConfigMap[this] = value
}

/**
* Converts a [CastPayload] object into its JS representation.
*/
Expand Down

0 comments on commit e239fce

Please sign in to comment.