Skip to content

Commit

Permalink
Add a sample to start at a given time (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ authored Jan 15, 2024
1 parent 04e2875 commit a1c86d4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object NavigationRoutes {
const val trackingSample = "tracking_sample"
const val updatableSample = "updatable_sample"
const val smoothSeeking = "smoothSeeking_sample"
const val startAtGivenTime = "start_given_time_sample"

const val homeLists = "home_lists"
const val contentLists = "content_lists"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ fun ShowCaseList(navController: NavController) {
)

DemoListSectionView {
DemoListItemView(
title = stringResource(R.string.start_given_time_example),
modifier = itemModifier,
onClick = {
navController.navigate(
NavigationRoutes.startAtGivenTime
)
}
)

Divider()

DemoListItemView(
title = stringResource(R.string.adaptive),
modifier = itemModifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ fun NavGraphBuilder.showCasesNavGraph(navController: NavController) {
composable(NavigationRoutes.smoothSeeking, DemoPageView("smooth seeking", Levels)) {
SmoothSeekingShowCase()
}
composable(NavigationRoutes.startAtGivenTime, DemoPageView("start at given time", Levels)) {
StartAtGivenTimeExample()
}
}

private val Levels = listOf("app", "pillarbox", "showcase")
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.demo.ui.showcases

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.shared.di.PlayerModule
import ch.srgssr.pillarbox.demo.ui.player.PlayerView
import kotlin.time.Duration.Companion.minutes

/**
* Simple example to demonstrate how to start content at a given time (10min).
*/
@Composable
fun StartAtGivenTimeExample() {
val context = LocalContext.current
val player = remember {
PlayerModule.provideDefaultPlayer(context).apply {
setMediaItem(DemoItem.AppleBasic_16_9_TS_HLS.toMediaItem())
prepare()
play()
seekTo(10.minutes.inWholeMilliseconds)
}
}
DisposableEffect(player) {
onDispose {
player.release()
}
}
PlayerView(player = player)
}
1 change: 1 addition & 0 deletions pillarbox-demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
<string name="update_media_item_example">Updatable media metadata</string>
<string name="smooth_seeking_example">Smooth seeking</string>
<string name="navigate_up">Navigate up</string>
<string name="start_given_time_example">Start at given time (10min)</string>
</resources>

0 comments on commit a1c86d4

Please sign in to comment.