From 7fde45fe0434c1f5735cc457d434b1b263e71b9d Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 18 Oct 2024 10:35:34 +0200 Subject: [PATCH] Cleanup code --- .../player/reactnative/MediaSessionModule.kt | 25 ------------------- .../player/reactnative/PlayerModule.kt | 15 ----------- .../player/reactnative/RNPlayerView.kt | 16 ++---------- 3 files changed, 2 insertions(+), 54 deletions(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionModule.kt index a3628093..301f25b1 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/MediaSessionModule.kt @@ -26,8 +26,6 @@ class MediaSessionModule(context: ReactApplicationContext) : BitmovinBaseModule( val serviceBinder = _serviceBinder.asStateFlow() inner class MediaSessionServiceConnection: ServiceConnection { - // we need a promise here, so that we can resolve it here instead of in setupMediaSession - // subclass ServiceConnection and pass promise 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 MediaSessionPlaybackService.ServiceBinder @@ -40,16 +38,8 @@ class MediaSessionModule(context: ReactApplicationContext) : BitmovinBaseModule( } } - - // [!!!] -- on new sources, the media session does not get overridden - // ISSUE: whenever a player instance is created the service does not get - // updated/overridden with that instance. - // Because in player.ts we call `setupMediaSession` on `initialize()`. @ReactMethod fun setupMediaSession(playerId: NativeId) { - // if there is an existing media session session, change its content - // the change should be on play actually, not on player creation - this@MediaSessionModule.playerId = playerId val intent = Intent(context, MediaSessionPlaybackService::class.java) intent.action = Intent.ACTION_MEDIA_BUTTON @@ -67,19 +57,4 @@ class MediaSessionModule(context: ReactApplicationContext) : BitmovinBaseModule( nativeId: NativeId = playerId, playerModule: PlayerModule? = context.playerModule, ): Player = playerModule?.getPlayerOrNull(nativeId) ?: throw IllegalArgumentException("Invalid PlayerId $nativeId") - - /// FINE - // - add LockScreenConfig serializers - // - add a lock-screen control sample: only there the config is set to true - // - fix player is paused when app is minimized: see android codebase: implement Activity lfiecycle onStart and onStop and detach player } - -// ISSUE2 -- if I start playback, minimize, and restart playback. I should -// re-fetch the state of the player from the service and update -// the player in the view - -// ISSUE3 -- if I start playback, minimize the app, the playback gets paused. -// It should not (it is background playback) - -// ISSUE4 -- if `loadSource()` is a different source than the one playing in the -// service, load that instead. 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 94044a78..f1733a53 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt @@ -1,8 +1,5 @@ package com.bitmovin.player.reactnative -import android.content.ComponentName -import android.content.ServiceConnection -import android.os.IBinder import android.util.Log import com.bitmovin.analytics.api.DefaultMetadata import com.bitmovin.player.api.Player @@ -16,11 +13,8 @@ import com.bitmovin.player.reactnative.converter.toAnalyticsDefaultMetadata import com.bitmovin.player.reactnative.converter.toJson import com.bitmovin.player.reactnative.converter.toPlayerConfig import com.bitmovin.player.reactnative.extensions.mapToReactArray -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 import java.security.InvalidParameterException private const val MODULE_NAME = "PlayerModule" @@ -98,12 +92,7 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex ) } - // FINAL: (ideas) - // If config is enabled, create the Intent here to start/bind the service -- setupMediaSession() - // Put the nativeId in the thread - if (playerConfig.lockScreenControlConfig.isEnabled) { -// playerConfig.playbackConfig promise.unit.resolveOnUiThread { mediaSessionModule .setupMediaSession(nativeId) @@ -111,10 +100,6 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex } } - // FINAL: 2 issues to solve: - // - where is the player created - // - how the player instance is given to the service (binder setting player vs playerId passing) - /** * Load the source of the given [nativeId] with `config` options from JS. * @param nativeId Target player. 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 c216aef2..d2e2c14d 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt @@ -18,7 +18,6 @@ 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 @@ -117,13 +116,10 @@ class RNPlayerView( context.mediaSessionModule?.serviceBinder?.value?.player = value } - private var oldPlayer: Player? = null - private val activityLifecycleObserver = object : DefaultLifecycleObserver { // Don't stop the player when going to background override fun onStart(owner: LifecycleOwner) { if (mediaSessionServicePlayer != null) { - oldPlayer = player player = mediaSessionServicePlayer } playerView?.onStart() @@ -140,18 +136,10 @@ class RNPlayerView( override fun onStop(owner: LifecycleOwner) { if (player?.config?.lockScreenControlConfig?.isEnabled == false) { mediaSessionServicePlayer = null - } - else { + } else { player = null } -// if (mediaSessionServicePlayer != null) { -//// context.mediaSessionModule?.serviceBinder?.value?.player = null -//// if (mediaSessionServicePlayer != player) { -//// mediaSessionServicePlayer = null -//// } -// -// player = oldPlayer -// } + playerView?.onStop() }