Skip to content

Commit

Permalink
live iframe support (badly)
Browse files Browse the repository at this point in the history
  • Loading branch information
probablybenallen committed Nov 18, 2022
1 parent 29967d6 commit 88b6ab5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
6 changes: 5 additions & 1 deletion components/LiveFeaturedPlayerBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const LiveModal = ({ channel }: { channel: channel }) => {
width: "100%",
}}
>
<VideoPlayer options={videoJSOptions} time={0} />
<VideoPlayer
options={videoJSOptions}
time={0}
iframe={channel.outputType == "iframe" ? channel.outputURL : null}
/>
<br />
</div>
<div style={{ flex: 1 }}>
Expand Down
18 changes: 18 additions & 0 deletions components/VideoPlayer/VideoPlayer.css
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,21 @@
.video-js:hover .vjs-big-play-button {
outline: none;
}

.container {
position: relative;
overflow: hidden;
width: 100%;
padding-top: 56.25%; /* 16:9 Aspect Ratio (divide 9 by 16 = 0.5625) */
}

/* Then style the iframe to fit in the container div with full height and width */
.responsive-iframe {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
}
16 changes: 15 additions & 1 deletion components/VideoPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import overlay from "videojs-titleoverlay";
export const VideoJS = (props) => {
const videoRef = useRef(null);
const playerRef = useRef(null);
const { options, onReady, time, title } = props;
const { options, onReady, time, title, iframe } = props;

useEffect(() => {
// make sure Video.js player is only initialized once
Expand Down Expand Up @@ -101,6 +101,20 @@ export const VideoJS = (props) => {
};
}, [playerRef]);

if (iframe)
return (
<div className="container">
<iframe
className="responsive-iframe"
src={options.sources[0].src}
title={title}
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
/>
</div>
);

return (
<div data-vjs-player>
<video ref={videoRef} className="video-js" />
Expand Down
6 changes: 5 additions & 1 deletion pages/watch/live/[liveURLName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export default function WatchLive({ channel }: { channel: channel }) {
<Link href="/watch/live">&larr; Back to live channels</Link>
<YstvHead title={`Live - ${channel.name}`} />
<h1>Live - {channel.name}</h1>
<VideoPlayer options={videoJSOptions} time={0} />
<VideoPlayer
options={videoJSOptions}
time={0}
iframe={channel.outputType == "iframe" ? channel.outputURL : null}
/>
<p>{channel.description}</p>
</div>
);
Expand Down

0 comments on commit 88b6ab5

Please sign in to comment.