diff --git a/demo/scripts/controllers/ContentList.tsx b/demo/scripts/controllers/ContentList.tsx index 1b91b72517..9ece7b4724 100644 --- a/demo/scripts/controllers/ContentList.tsx +++ b/demo/scripts/controllers/ContentList.tsx @@ -260,10 +260,12 @@ function getKeySystemsOption( function ContentList({ loadVideo, + preloadVideo, showOptions, onOptionToggle, }: { loadVideo: (opts: ILoadVideoOptions) => void; + preloadVideo: (opts: ILoadVideoOptions) => void; showOptions: boolean; onOptionToggle: () => void; }): React.JSX.Element { @@ -327,6 +329,43 @@ function ContentList({ [loadVideo], ); + /** + * Load the given displayed content through the player. + * @param {Object|null} content + */ + const preloadContent = React.useCallback( + (content: IDisplayedContent) => { + const { + url, + transport, + fallbackKeyError, + fallbackLicenseRequest, + isLowLatency, + drmInfos, + } = content; + + getKeySystemsOption(drmInfos ?? [], { + fallbackKeyError: !!fallbackKeyError, + fallbackLicenseRequest: !!fallbackLicenseRequest, + }).then( + (keySystems) => { + preloadVideo({ + url: url ?? "", + transport: transport ?? "", + textTrackMode: "html", + lowLatencyMode: isLowLatency, + keySystems, + }); + }, + () => { + /* eslint-disable-next-line no-console */ + console.error("Could not construct key systems option"); + }, + ); + }, + [loadVideo], + ); + /** * Load a custom content entered in a custom link. * @param {string} url @@ -362,6 +401,41 @@ function ContentList({ ], ); + /** + * Load a custom content entered in a custom link. + * @param {string} url + * @param {Array.} drmInfos + */ + const preloadUrl = React.useCallback( + (url: string, drmInfos: IDrmInfo[]) => { + getKeySystemsOption(drmInfos, { + fallbackKeyError: !!shouldFallbackOnKeyError, + fallbackLicenseRequest: !!shouldFallbackOnLicenseReqError, + }).then( + (keySystems) => { + preloadVideo({ + url: url, + transport: transportType.toLowerCase(), + textTrackMode: "html", + lowLatencyMode: isLowLatencyChecked, + keySystems, + }); + }, + () => { + /* eslint-disable-next-line no-console */ + console.error("Could not construct key systems option"); + }, + ); + }, + [ + loadVideo, + shouldFallbackOnKeyError, + shouldFallbackOnLicenseReqError, + transportType, + isLowLatencyChecked, + ], + ); + /** * Change the content chosen in the list. * @param {number} index - index in the lsit @@ -530,6 +604,22 @@ function ContentList({ } }; + const onClickPreload = () => { + if (contentChoiceIndex === 0) { + const drmInfos = [ + { + licenseServerUrl, + serverCertificateUrl, + drm: chosenDRMType, + customKeySystem, + }, + ]; + preloadUrl(currentManifestURL, drmInfos); + } else { + preloadContent(contentsToSelect[contentChoiceIndex]); + } + }; + const saveCurrentContent = () => { const contentToSave: IContentInfo = { name: contentNameField, @@ -766,6 +856,13 @@ function ContentList({ value={String.fromCharCode(0xf144)} disabled={false} /> +