Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DE-7267: HLS-I option to disable intermission #47

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/interstitial/InterstitialPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,17 @@ export const InterstitialPlayer = React.memo((props: InterstitialPlayerProps) =>
{...props}
onStartClick={async () => {
await load()
if (props.intermissionDuration === null) {
await playerRef.current.unpause()
}
}}
onLoopEnded={async () => {
props.onLoopEnded?.()
await playerRef.current.reset()
await load()
if (props.intermissionDuration === null) {
await playerRef.current.unpause()
}
}}
onIntermissionEnded={async () => {
props.onIntermissionEnded?.()
Expand Down
19 changes: 12 additions & 7 deletions src/interstitial/components/OverlayHlsi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type Props = {
loop?: boolean
/**
* Intermission duration in seconds, defaults to 3.
* Set to `null` to disable the intermission.
*/
intermissionDuration?: number | null
/**
Expand Down Expand Up @@ -102,7 +103,7 @@ export type Props = {
*/
export const InterstitialOverlay = React.memo((props: Props) => {
const [hadInteraction, setHadInteraction] = useState(false)
const [intermission, setIntermission] = useState(true)
const [intermission, setIntermission] = useState(props.intermissionDuration !== null)
const interstitial = useHlsInterstitial()
const loop = props.loop ?? true

Expand All @@ -121,10 +122,12 @@ export const InterstitialOverlay = React.memo((props: Props) => {
hasPauseButton = props.interstitialControls.pause
}

const endIntermission = useCallback(() => {
setIntermission(false)
props.onIntermissionEnded?.()
}, [props.onIntermissionEnded])
const onCountdownEnded = useCallback(() => {
if (props.intermissionDuration !== null) {
setIntermission(false)
props.onIntermissionEnded?.()
}
}, [props.onIntermissionEnded, props.intermissionDuration])

const onStartClick = useCallback(() => {
setHadInteraction(true)
Expand All @@ -134,7 +137,9 @@ export const InterstitialOverlay = React.memo((props: Props) => {
usePrestoUiEventHlsi('ended', () => {
if (loop) {
props.onLoopEnded?.()
setIntermission(true)
if (props.intermissionDuration !== null) {
setIntermission(true)
}
} else {
props.onEnded?.()
}
Expand Down Expand Up @@ -177,7 +182,7 @@ export const InterstitialOverlay = React.memo((props: Props) => {
return <CountDown
render={props.renderIntermission}
seconds={duration}
onDone={endIntermission}
onDone={onCountdownEnded}
/>
}

Expand Down
Loading