Skip to content

Instantly share code, notes, and snippets.

@daviseford
Last active October 3, 2019 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviseford/c21b271fa923d9c8d274a25b1379cc62 to your computer and use it in GitHub Desktop.
Save daviseford/c21b271fa923d9c8d274a25b1379cc62 to your computer and use it in GitHub Desktop.
React Bootstrap Webm Component with Fallback Image
type TWebmComponent = React.FC<{ videoUrl: string; fallbackUrl: string; description: string; onClick?: (e) =>void }>
const WebmComponent: TWebmComponent = ({ videoUrl, fallbackUrl, description, onClick = () => null }) => {
const supportsWebm = !!document.createElement('video').canPlayType
return (
<>
<figure className="figure">
<a
href={supportsWebm ? videoUrl : fallbackUrl}
target="_blank"
rel="noopener noreferrer"
onClick={onClick}
>
<video
preload="auto"
loop={true}
poster={fallbackUrl}
autoPlay={true}
className="figure-img img-fluid rounded img-thumbnail"
>
<source src={videoUrl} type="video/webm"></source>
<source src={videoUrl} type="video/mp4"></source>
</video>
</a>
<figcaption className="figure-caption text-center">{description}</figcaption>
</figure>
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment