From 49945624a1fbf70083d290e001cd8ee836f40e50 Mon Sep 17 00:00:00 2001 From: Kevin Rocard Date: Wed, 6 Dec 2023 10:00:44 +0100 Subject: [PATCH] fix: rename&use runOnMainLooperAndLogException --- .../player/reactnative/RNPlayerViewManager.kt | 14 +++++++------- .../extensions/ReactContextExtension.kt | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt index 8af80bf6..367a45f7 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt @@ -11,10 +11,10 @@ import com.bitmovin.player.api.ui.ScalingMode import com.bitmovin.player.api.ui.UiConfig import com.bitmovin.player.reactnative.converter.toRNPlayerViewConfigWrapper import com.bitmovin.player.reactnative.converter.toRNStyleConfigWrapperFromPlayerConfig +import com.bitmovin.player.reactnative.extensions.customMessageHandlerModule import com.bitmovin.player.reactnative.extensions.getBooleanOrNull import com.bitmovin.player.reactnative.extensions.getModule import com.bitmovin.player.reactnative.extensions.playerModule -import com.bitmovin.player.reactnative.ui.CustomMessageHandlerModule import com.bitmovin.player.reactnative.ui.FullscreenHandlerModule import com.bitmovin.player.reactnative.ui.RNPictureInPictureHandler import com.facebook.react.bridge.* @@ -201,9 +201,9 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple } private fun setPictureInPicture(view: RNPlayerView, isPictureInPictureRequested: Boolean) { - runInMainLooperAndLogException { + runOnMainLooperAndLogException { val playerView = view.playerView ?: throw IllegalStateException("The player view is not yet created") - if (playerView.isPictureInPicture != isPictureInPictureRequested) return@runInMainLooperAndLogException + if (playerView.isPictureInPicture != isPictureInPictureRequested) return@runOnMainLooperAndLogException if (isPictureInPictureRequested) { playerView.enterPictureInPicture() } else { @@ -213,7 +213,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple } private fun setScalingMode(view: RNPlayerView, scalingMode: String) { - Handler(Looper.getMainLooper()).post { + runOnMainLooperAndLogException { view.playerView?.scalingMode = ScalingMode.valueOf(scalingMode) } } @@ -225,7 +225,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple private fun attachCustomMessageHandlerBridge(view: RNPlayerView) { view.playerView?.setCustomMessageHandler( - context.getModule() + context.customMessageHandlerModule ?.getInstance(customMessageHandlerBridgeId) ?.customMessageHandler, ) @@ -237,7 +237,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple * @param playerId `Player` instance id inside `PlayerModule`'s registry. */ private fun attachPlayer(view: RNPlayerView, playerId: NativeId, playerConfig: ReadableMap?) { - runInMainLooperAndLogException { + runOnMainLooperAndLogException { val player = playerId.let { context.playerModule?.getPlayerOrNull(it) } ?: throw InvalidParameterException("Cannot create a PlayerView, invalid playerId was passed.") val playbackConfig = playerConfig?.getMap("playbackConfig") @@ -285,7 +285,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple } } - private inline fun runInMainLooperAndLogException(crossinline block: () -> Unit) { + private inline fun runOnMainLooperAndLogException(crossinline block: () -> Unit) { Handler(Looper.getMainLooper()).post { try { block() 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 76e23203..43e00bc9 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 @@ -4,6 +4,7 @@ import com.bitmovin.player.reactnative.DrmModule import com.bitmovin.player.reactnative.OfflineModule import com.bitmovin.player.reactnative.PlayerModule import com.bitmovin.player.reactnative.SourceModule +import com.bitmovin.player.reactnative.ui.CustomMessageHandlerModule import com.facebook.react.bridge.* import com.facebook.react.uimanager.UIManagerModule @@ -16,3 +17,4 @@ val ReactApplicationContext.sourceModule get() = getModule() val ReactApplicationContext.offlineModule get() = getModule() val ReactApplicationContext.uiManagerModule get() = getModule() val ReactApplicationContext.drmModule get() = getModule() +val ReactApplicationContext.customMessageHandlerModule get() = getModule()