Last active
October 3, 2019 12:19
-
-
Save daviseford/c21b271fa923d9c8d274a25b1379cc62 to your computer and use it in GitHub Desktop.
React Bootstrap Webm Component with Fallback Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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