Skip to content

Commit

Permalink
DE-7267: HLS-I option to disable intermission
Browse files Browse the repository at this point in the history
  • Loading branch information
fingerartur committed Sep 9, 2024
1 parent c3c354d commit 80e4140
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
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

0 comments on commit 80e4140

Please sign in to comment.