-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement search bar and video chapters
- Loading branch information
Showing
13 changed files
with
1,483 additions
and
827 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": ["next/core-web-vitals", "prettier"] | ||
"extends": ["next/core-web-vitals", "prettier"], | ||
"rules": { | ||
"@next/next/no-img-element": "off" | ||
} | ||
} |
This file contains 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
90 changes: 90 additions & 0 deletions
90
app/courses/[courseId]/media/[mediaId]/ContentMediaDisplay.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"use client"; | ||
import { ContentMediaDisplayFragment$key } from "@/__generated__/ContentMediaDisplayFragment.graphql"; | ||
import { ContentMediaDisplayVideoFragment$key } from "@/__generated__/ContentMediaDisplayVideoFragment.graphql"; | ||
import { PdfViewer } from "@/components/PdfViewer"; | ||
import { MediaPlayer, MediaProvider } from "@vidstack/react"; | ||
import { | ||
defaultLayoutIcons, | ||
DefaultVideoLayout, | ||
} from "@vidstack/react/player/layouts/default"; | ||
import "@vidstack/react/player/styles/default/layouts/video.css"; | ||
import "@vidstack/react/player/styles/default/theme.css"; | ||
import { useFragment } from "react-relay"; | ||
import { graphql } from "relay-runtime"; | ||
|
||
export function ContentMediaDisplay({ | ||
_record, | ||
onProgressChange, | ||
}: { | ||
_record: ContentMediaDisplayFragment$key; | ||
onProgressChange: (fraction: number) => void; | ||
}) { | ||
const mediaRecord = useFragment( | ||
graphql` | ||
fragment ContentMediaDisplayFragment on MediaRecord { | ||
type | ||
name | ||
downloadUrl | ||
...ContentMediaDisplayVideoFragment | ||
} | ||
`, | ||
_record | ||
); | ||
|
||
switch (mediaRecord.type) { | ||
case "VIDEO": | ||
return <VideoPlayer _video={mediaRecord} />; | ||
case "PRESENTATION": | ||
case "DOCUMENT": | ||
return ( | ||
<PdfViewer | ||
onProgressChange={onProgressChange} | ||
url={mediaRecord.downloadUrl} | ||
/> | ||
); | ||
case "IMAGE": | ||
// eslint-disable-next-line @next/next/no-img-element | ||
return ( | ||
<img | ||
alt={mediaRecord.name} | ||
src={mediaRecord.downloadUrl} | ||
className="max-h-md flex justify-center mx-auto" | ||
></img> | ||
); | ||
default: | ||
return <>Unsupported media type</>; | ||
} | ||
} | ||
|
||
export function VideoPlayer({ | ||
_video, | ||
}: { | ||
_video: ContentMediaDisplayVideoFragment$key; | ||
}) { | ||
const mediaRecord = useFragment( | ||
graphql` | ||
fragment ContentMediaDisplayVideoFragment on MediaRecord { | ||
type | ||
name | ||
downloadUrl | ||
segments { | ||
id | ||
... on VideoRecordSegment { | ||
startTime | ||
transcript | ||
thumbnail | ||
title | ||
} | ||
} | ||
} | ||
`, | ||
_video | ||
); | ||
|
||
return ( | ||
<MediaPlayer src={mediaRecord.downloadUrl}> | ||
<MediaProvider /> | ||
<DefaultVideoLayout icons={defaultLayoutIcons} /> | ||
</MediaPlayer> | ||
); | ||
} |
This file contains 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
Oops, something went wrong.