mediaplayer
README.md
:OCMediaPlayer
This OCMediaPlayer
is a custom Jetpack Compose component designed to stream videos.
:How to use OCMediaPlayer
-
Add the necessary imports:
import your.package.name.OCMediaPlayer
-
Use the
OCMediaPlayer
within your Composable:OCMediaPlayer(
player = player,
onFullScreenToggle = onPlayerEnterFullScreen,
isFullScreen = false,
)
-
Set the player media by invoking OCMediaPlayerViewModel.setPlayerMedia(ocMediaPlayerConfig: OCMediaPlayerConfig) from your Composable.
-
The auto play configuration can be modified by changing the playWhenReady config of OCMediaPlayerConfig. Default config is playWhenReady = true.
var isPlayedInitialized by rememberSaveable(Boolean) {
mutableStateOf(false)
}
LaunchedEffect(isPlayedInitialized) {
if (isPlayedInitialized.not()) {
setPlayerMedia(
OCMediaPlayerConfig(
sourceUrl = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
)
)
isPlayedInitialized = true
}
} -
Update the navigation of your component with the video player full screen navigation.
composable(
route = YourComponentRoute,
) {
HideFullScreen(activity = navController.context.findActivity())
YourComponentRoute(onPlayerEnterFullScreen)
}
composable(
route = videoFullScreenTestRoute
) {
val backStackEntry = remember (it) {
navController.getBackStackEntry("$yourComponentNavigationRoute")
}
val mediaPlayerViewModel: OCMediaPlayerViewModel = hiltViewModel(backStackEntry)
ShowFullScreen(activity = navController.context.findActivity())
VideoPlayerFullScreenRoute(
onExitFullScreen = onExitFullScreen,
mediaPlayerViewModel = mediaPlayerViewModel
)
}