Skip to content

Commit

Permalink
feat: add Android parsing for new PlayerViewConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
strangesource committed Oct 18, 2023
1 parent f580652 commit 4e9cf65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.bitmovin.player.api.Player
import com.bitmovin.player.api.event.Event
import com.bitmovin.player.api.event.PlayerEvent
import com.bitmovin.player.api.event.SourceEvent
import com.bitmovin.player.api.ui.PlayerViewConfig
import com.bitmovin.player.reactnative.converter.JsonConverter
import com.bitmovin.player.reactnative.ui.RNPictureInPictureDelegate
import com.bitmovin.player.reactnative.ui.RNPictureInPictureHandler
Expand Down Expand Up @@ -149,6 +150,11 @@ class RNPlayerView(val context: ReactApplicationContext) :
*/
var pictureInPictureConfig: RNPictureInPictureHandler.PictureInPictureConfig? = null

/**
* Configures the visual presentation and behaviour of the [playerView].
*/
var config: PlayerViewConfig? = null

/**
* Whether this view should pause video playback when activity's onPause is called.
* By default, `shouldPausePlaybackOnActivityPause` is set to false when entering PiP mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.util.Log
import android.view.ViewGroup.LayoutParams
import com.bitmovin.player.PlayerView
import com.bitmovin.player.api.ui.ScalingMode
import com.bitmovin.player.api.ui.PlayerViewConfig
import com.bitmovin.player.reactnative.converter.JsonConverter
import com.bitmovin.player.reactnative.extensions.getBooleanOrNull
import com.bitmovin.player.reactnative.extensions.getModule
Expand Down Expand Up @@ -187,6 +188,11 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
view.pictureInPictureConfig = JsonConverter.toPictureInPictureConfig(pictureInPictureConfig)
}

@ReactProp(name = "config")
fun setConfig(view: RNPlayerView, config: ReadableMap?) {
view.config = if (config != null) JsonConverter.toPlayerViewConfig(config) else null
}

private fun attachFullscreenBridge(view: RNPlayerView, fullscreenBridgeId: NativeId) {
Handler(Looper.getMainLooper()).post {
view.playerView?.setFullscreenHandler(
Expand Down Expand Up @@ -261,7 +267,11 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
Log.e(MODULE_NAME, "Cannot create a PlayerView, because no activity is attached.")
return@post
}
val playerView = PlayerView(currentActivity, player)
val playerView = PlayerView(
currentActivity,
player,
view.config ?: PlayerViewConfig(),
)
playerView.layoutParams = LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ import com.bitmovin.player.api.source.SourceConfig
import com.bitmovin.player.api.source.SourceOptions
import com.bitmovin.player.api.source.SourceType
import com.bitmovin.player.api.source.TimelineReferencePoint
import com.bitmovin.player.api.ui.PlayerViewConfig
import com.bitmovin.player.api.ui.ScalingMode
import com.bitmovin.player.api.ui.StyleConfig
import com.bitmovin.player.api.ui.UiConfig
import com.bitmovin.player.reactnative.BitmovinCastManagerOptions
import com.bitmovin.player.reactnative.extensions.getBooleanOrNull
import com.bitmovin.player.reactnative.extensions.getName
Expand Down Expand Up @@ -1147,6 +1149,17 @@ class JsonConverter {
isEnabled = it.getBoolean("isEnabled"),
)
}

/**
* Converts the [json] to a `RNUiConfig` object.
*/
fun toPlayerViewConfig(json: ReadableMap) = PlayerViewConfig(
uiConfig = UiConfig.WebUi(
playbackSpeedSelectionEnabled = json.getMap("uiConfig")
?.getBooleanOrNull("playbackSpeedSelectionEnabled")
?: true,
),
)
}
}

Expand Down

0 comments on commit 4e9cf65

Please sign in to comment.