Skip to content

Commit

Permalink
Simple video player
Browse files Browse the repository at this point in the history
  • Loading branch information
Winston-Hsiao committed Sep 18, 2024
1 parent ae8b003 commit 635264e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
53 changes: 53 additions & 0 deletions frontend/src/components/VideoDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react";

interface VideoDemoProps {
src: string;
type: "youtube" | "local";
title?: string;
autoplay?: boolean;
}

export const VideoDemo: React.FC<VideoDemoProps> = ({
src,
type,
title,
autoplay = false,
}) => {
if (type === "youtube") {
const youtubeParams = new URLSearchParams({
autoplay: autoplay ? "1" : "0",
controls: "0",
showinfo: "0",
rel: "0",
loop: "1",
playlist: src.split("/").pop() || "",
}).toString();

const embedUrl = `${src}?${youtubeParams}`;

return (
<iframe
className="w-full h-full"
src={embedUrl}
title={title || "YouTube video player"}
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerPolicy="strict-origin-when-cross-origin"
allowFullScreen
></iframe>
);
} else {
return (
<video
className="w-full h-full object-cover"
autoPlay={autoplay}
loop
muted
playsInline
>
<source src={src} type="video/mp4" />
Your browser does not support the video tag.
</video>
);
}
};
17 changes: 7 additions & 10 deletions frontend/src/components/home/KLangDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react";

import { VideoDemo } from "@/components/VideoDemo";
import { Button } from "@/components/ui/button";

export default function KLangDemo() {
Expand Down Expand Up @@ -35,16 +36,12 @@ speakPhrase("Hello, I am a robot.");`,
<div className="space-y-4">
<div className="flex flex-col items-center space-y-4 text-center">
<div className="w-full max-w-4xl aspect-video overflow-hidden rounded-xl border bg-gray-11">
<video
className="w-full h-full object-cover"
autoPlay
loop
muted
playsInline
>
<source src="/placeholder.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
<VideoDemo
src="https://www.youtube.com/embed/Y-mD7Cp9KSs"
type="youtube"
title="Minimal PPO Implementation"
autoplay={true}
/>
</div>
</div>
</div>
Expand Down

0 comments on commit 635264e

Please sign in to comment.