Skip to content

Commit

Permalink
DE-7270: Add autoplay to HLS-I (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingerartur authored Sep 10, 2024
1 parent c040815 commit 1f48dba
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
5 changes: 4 additions & 1 deletion app/src/InterstitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { InterstitialPlayer } from '../../src'
* A page featuring the HLS interstitial player.
*/
export const InterstitialPage = () => {
const [mounted, setMounted] = useState(true)
const [mounted, setMounted] = useState(false)

const toggleMounted = () => {
setMounted(m => !m)
Expand All @@ -29,7 +29,10 @@ export const InterstitialPage = () => {
// url: 'https://content.players.castlabs.com/api-interstitials-v3/vod-preroll.m3u8',
type: clpp.Type.HLS,
},
autoplay: true,
}}
hasStartButton={false}
intermissionDuration={null}
hasTopControlsBar={false}
interstitialOptions={{
config: {
Expand Down
1 change: 0 additions & 1 deletion app/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ nav button:hover {
}

.in-container {
width: 1000px;
}

.in-video-container {
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@babel/preset-env": "^7.22.4",
"@babel/preset-react": "^7.22.3",
"@babel/preset-typescript": "^7.21.5",
"@castlabs/prestoplay": "^6.16.1-beta.4",
"@castlabs/prestoplay": "^6.16.1-beta.6",
"@finga/eslint-config": "^1.2.1",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-image": "^3.0.2",
Expand Down
15 changes: 15 additions & 0 deletions src/interstitial/InterstitialPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export type InterstitialPlayerProps = {
* Enable focus-based keyboard interactivity. Default: true.
*/
enableFocus?: boolean
/**
* If true, the start button is shown which has to be clicked
* for playback/countdown to begin. Default: true.
*/
hasStartButton?: boolean
}

/**
Expand All @@ -133,11 +138,20 @@ export const InterstitialPlayer = React.memo((props: InterstitialPlayerProps) =>
const load = async () => {
try {
await playerRef.current.loadHlsi(props.asset)
if (props.asset.autoplay) {
await playerRef.current.unpause()
}
} catch (e) {
console.error('Interstitial player Failed to load asset', e)
}
}

useEffect(() => {
if (props.asset && props.asset.autoplay) {
void load()
}
}, [])

useEffect(() => {
if (props.onPlayerChanged) {
playerRef.current.onUIEvent('playerChanged', props.onPlayerChanged)
Expand Down Expand Up @@ -189,6 +203,7 @@ export const InterstitialPlayer = React.memo((props: InterstitialPlayerProps) =>
props.onIntermissionEnded?.()
await playerRef.current.unpause()
}}
hasStartButton={props.hasStartButton ?? true}
/>
</PlayerSurfaceHlsi>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/interstitial/components/OverlayHlsi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export type Props = {
* Player controls to shown during interstitial playback.
*/
interstitialControls?: InterstitialControls
/**
* If true, the start button is shown which has to be clicked
* for playback/countdown to begin.
*/
hasStartButton: boolean
}

/**
Expand All @@ -112,6 +117,7 @@ export const InterstitialOverlay = React.memo((props: Props) => {
let hasAudioControls = props.hasAudioControls ?? false
let hasTime = true
let hasPauseButton = true
const hasStartButton = props.hasStartButton ?? true
if (props.interstitialControls && interstitial) {
if (props.interstitialControls.seekButtons === false) {
seekStep = 0
Expand Down Expand Up @@ -173,7 +179,7 @@ export const InterstitialOverlay = React.memo((props: Props) => {
)
}

if (!hadInteraction) {
if (!hadInteraction && hasStartButton) {
return <StartButton onClick={onStartClick}/>
}

Expand Down

0 comments on commit 1f48dba

Please sign in to comment.