Cannot get Media Preview Thumbnail to render
shenders13 opened this issue Β· comments
Hi Media Chrome folks π
The problem
I'm running into some issues getting the "Media Preview Thumbnail" images to appear when the user hovers over the media time range.
When I hover over the time range, the small badge showing the current time appears, but not the "Preview Thumbnail"
![Screenshot 2023-11-11 at 7 59 59 pm](https://private-user-images.githubusercontent.com/15011940/282277205-d6fb799c-7d48-4e6e-b5c7-707093632253.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAzNTAxNTAsIm5iZiI6MTcyMDM0OTg1MCwicGF0aCI6Ii8xNTAxMTk0MC8yODIyNzcyMDUtZDZmYjc5OWMtN2Q0OC00ZTZlLWI1YzctNzA3MDkzNjMyMjUzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA3VDEwNTczMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWUzYTYzY2ZkMTBjMjE2MGJiOTY4MGNhZDdmZDQ3YjUzZDY2M2NhMGU1MjI1MDdjNTcxZTEwMzdiZWY1OGI4NjYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.zjEwV8Qe2R8fGP2MjxZSisWO2bIJ_wrmH3Tiyv3ZV-M)
I am on version 1.5.2
of media-chrome
Attempt 1 - Render the MediaPrevewThumbnail component with mediaPreviewImage and mediaPreviewCoords props
I saw in the Media Chrome docs (here) that I can render <MediaPreviewThumbnail />
like so:
import { MediaPreviewThumbnail } from 'media-chrome/dist/react';
<MediaPreviewThumbnail
mediaPreviewImage="https://image.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/storyboard.vtt"
mediaPreviewCoords="284 640 284 160"
/>
I have tried it with and without the mediaPreviewCoords
but no luck. I can see the file being downloaded successfully in the network tab.
No preview image appeared π’
Attempt 2 - Render the MediaPrevewThumbnail but put the mediaPreviewImage props on the MediaController
<MediaController
autohide={autohide} // https://www.media-chrome.org/en/media-controller#autohide
className={sizeClasses}
defaultStreamType={defaultStreamType} // https://www.media-chrome.org/en/media-controller#default-stream-type
ref={mediaControllerRef}
style={{
'--media-control-background': 'transparent',
'--media-control-hover-background': 'transparent',
'--media-control-padding': '0',
}}
nohotkeys
// ADD mediaPreviewImage PROP TO MEDIA CONTROLLER BELOW
mediaPreviewImage="https://image.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/storyboard.vtt"
mediaPreviewCoords="284 640 284 160"
>
<MediaPreviewThumbnail />
No preview image appeared π’
Attempt 3 - Render a element inside the video element
I saw in these docs that you could render a <track />
element inside the <video>
element.
Here was my code:
<video
className="w-full h-full"
crossOrigin="anonymous"
muted={initiallyMuted}
playsInline
poster={loadingImageSrc}
ref={videoRef}
slot="media"
>
<track
default
label="thumbnails"
kind="metadata"
src="https://image.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/storyboard.vtt"
/>
</video>
No preview image appeared in this case either π’
Attempt 4 - Adding a mediaPreviewImage
prop to the <MediaTimeRange />
component
At this point I was trying random things - but I discovered that if you add a mediaPreviewImage
prop to the <MediaTimeRange/>
component, we end up with the faded outline of where the preview image should be (but alas, no actual image).
![Screenshot 2023-11-11 at 8 13 49 pm](https://private-user-images.githubusercontent.com/15011940/282277591-512634c2-e452-4fd5-9af2-02f9146337b1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAzNTAxNTAsIm5iZiI6MTcyMDM0OTg1MCwicGF0aCI6Ii8xNTAxMTk0MC8yODIyNzc1OTEtNTEyNjM0YzItZTQ1Mi00ZmQ1LTlhZjItMDJmOTE0NjMzN2IxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA3VDEwNTczMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBjODE4ZDA0ZjNmZDkwYzVkY2E0YjdhYWEwNmY3ZWIzNDljZjIzYzVjOTczNzg3YmFjNGYzYTM5OWE1ZjAyMmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.5SQJBUalVkXlxPfCp9yd1E6tYhpDTrMzAhgrkdZhzFs)
My code:
return (
<div>
<MediaController
autohide={autohide}
className={sizeClasses}
defaultStreamType={defaultStreamType}
ref={mediaControllerRef}
style={{
'--media-control-background': 'transparent',
'--media-control-hover-background': 'transparent',
'--media-control-padding': '0',
}}
nohotkeys
>
<video
className="w-full h-full"
crossOrigin="anonymous"
muted={initiallyMuted}
playsInline
poster={loadingImageSrc}
ref={videoRef}
slot="media"
>
{/** I tried adding a a <track> here for the preview thumbnail*/}
<track
default
label="thumbnails"
kind="metadata"
src="https://image.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/storyboard.vtt"
/>
</video>
{/** Desktop Center: Loading Indicator */}
{isLoading && <div slot="centered-chrome" className="hidden md:flex opacity-100">
<MediaLoadingIndicator />
</div>}
<MediaControlBar className="pb-2 px-4 md:pb-4 z-raised">
<div className={clsx(hideControlBar ? 'hidden' : 'flex', 'flex-col w-full')}>
<div className="flex flex-row w-full">
{/** Mobile Control Bar: Left Section */}
{streamType === 'on-demand' ? (
<ControlBarGroup showOn="mobile-only">
<MediaTimeDisplay showDuration />
</ControlBarGroup>
) : null}
{/** Desktop Control Bar: Left Section */}
<ControlBarGroup showOn="desktop-only">
<PlayButton
isPlaying={isPlaying}
playButtonRef={mediaPlayButtonRef}
screen="desktop"
/>
<MuteButton />
<MediaTimeDisplay showDuration />
</ControlBarGroup>
{/** Desktop Control Bar: Center Section */}
<div
className="flex-1"
style={{ backgroundColor: 'var(--media-control-background)' }}
>
{isDesktop && streamType === 'on-demand' ? (
<div className="hidden md:flex h-full px-4">
<TimeRange />
<MediaPreviewThumbnail
mediaPreviewImage="https://image.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/storyboard.vtt"
mediapreviewcoords="284 640 284 160"
/>
</div>
) : null}
</div>
{/** Desktop & Mobile Control Bar: Right Section */}
<ControlBarGroup showOn="mobile-and-desktop">
<QualityButton
id="settings-button"
qualityOptions={{
activeLevel: activeVideoLevel,
levels: videoLevels,
selectLevel: setActiveVideoLevel,
}}
show={Boolean(hlsjs)}
/>
<TheaterModeButton {...theaterModeControls} />
<MediaPipButton className="hover:bg-initial" />
<MediaFullscreenButton className="hover:bg-initial" />
</ControlBarGroup>
</div>
{/** Mobile Time Range: Under Controls Section */}
{isMobile && streamType === 'on-demand' ? (
<div
className="flex-1 mt-3 flex md:hidden h-full"
style={{ backgroundColor: 'var(--media-control-background)' }}
>
<TimeRange />
</div>
) : null}
</div>
</MediaControlBar>
{children}
</MediaController>
</div>
);
Please help me understand why the preview image isn't appearing π Thanks team!
Any chance you could put a reproduction online?
What's in <TimeRange />
? Only MediaTimeRange
It should be option 3, that's correct.
https://www.media-chrome.org/docs/en/components/media-time-range#preview-thumbnails
Hi @luwes π
Of course, here is a small codesandbox that reproduces the issue.
Does anything jump out at you as wrong in terms of how I'm rendering the <track />
element?
![Screenshot 2023-11-12 at 4 02 18 pm](https://private-user-images.githubusercontent.com/15011940/282334594-f7112d55-f4b0-4a55-81f5-736deff3c084.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAzNTAxNTAsIm5iZiI6MTcyMDM0OTg1MCwicGF0aCI6Ii8xNTAxMTk0MC8yODIzMzQ1OTQtZjcxMTJkNTUtZjRiMC00YTU1LTgxZjUtNzM2ZGVmZjNjMDg0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA3VDEwNTczMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc0N2FlZGQ5ZDE4MTU4MDJkYThkZDNlZTk3MGZiYjBlODY3MjUxNzAxNWRiMjljYjc5MTBlODM4NjRjOWIxN2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.xHC2xeERUvo9aKOoRF1sR0jkco-RXC_ks2v-mlZC-M4)
EDIT:
I added some console.logs
and found that the track element did not have any cues
. So this line in controller.js was aborting early.
When I add crossOrigin="anonymous"
to the parent video component, it works A-okay!
Ah yes, crossOrigin is required. Great you found the issue!