Skip to content

Android

The AndroidPlayer can be consumed directly, in which case, you’d be responsible for managing the lifecycle, responding to updates, and starting flows. To limit overhead, we provide the PlayerViewModel and PlayerFragment to couple the Player lifecycle with the Android lifecycle and remove this responsibility for general use cases. All that is needed is to provide concrete implementations of each and add the fragment to your app.

The PlayerViewModel requires an AsyncFlowIterator to be supplied in the constructor. The AsyncFlowIterator (aka FlowManager) is what tells Player which flows to run. This can be hardcoded into the view model or expected as an argument, as shown below.

class SimplePlayerViewModel(flows: AsyncFlowIterator) : PlayerViewModel(flows) {
override val plugins = listOf(ReferenceAssetsPlugin())
}

The PlayerFragment is a simple Android Fragment that only requires a specific PlayerViewModel to be defined. If your view model requires the AsyncFlowIterator to be passed as part of the constructor, you can leverage the PlayerViewModel.Factory to produce it, as shown below.

Specifically, this fragment takes a flow as an argument to the constructor and creates a single-flow AsyncFlowIterator instance using the pseudo-constructor helper.

class SimplePlayerFragment(override val flow: String) : PlayerFragment() {
override val playerViewModel by viewModels<SimplePlayerViewModel> {
PlayerViewModel.Factory(AsyncFlowIterator(flow), ::SimplePlayerViewModel)
}
}

The Android Player dependency automatically pulls source maps for the mobile JS bundles.

To optimize the release bundles, it is highly recommended to exclude .map files, as well as enabling R8 to strip out unused code from the final bundle.

buildTypes {
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
packagingOptions {
exclude("**/*.js.map")
}
}
}