Skip to content

Commit

Permalink
fix: rename&use runOnMainLooperAndLogException
Browse files Browse the repository at this point in the history
  • Loading branch information
krocard committed Dec 6, 2023
1 parent d77c955 commit 4994562
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand All @@ -225,7 +225,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple

private fun attachCustomMessageHandlerBridge(view: RNPlayerView) {
view.playerView?.setCustomMessageHandler(
context.getModule<CustomMessageHandlerModule>()
context.customMessageHandlerModule
?.getInstance(customMessageHandlerBridgeId)
?.customMessageHandler,
)
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -16,3 +17,4 @@ val ReactApplicationContext.sourceModule get() = getModule<SourceModule>()
val ReactApplicationContext.offlineModule get() = getModule<OfflineModule>()
val ReactApplicationContext.uiManagerModule get() = getModule<UIManagerModule>()
val ReactApplicationContext.drmModule get() = getModule<DrmModule>()
val ReactApplicationContext.customMessageHandlerModule get() = getModule<CustomMessageHandlerModule>()

0 comments on commit 4994562

Please sign in to comment.