Skip to content

Commit 8580acc

Browse files
Ahtesham QuraishAhtesham Quraish
authored andcommitted
fix: add support for mp4 videos
1 parent dab62ef commit 8580acc

3 files changed

Lines changed: 54 additions & 9 deletions

File tree

frontends/main/src/page-components/TiptapEditor/extensions/node/MediaEmbed/MediaEmbedNodeView.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { FullWidth, WideWidth, DefaultWidth } from "./Icons"
55
import { RiCloseLargeLine } from "@remixicon/react"
66
import { ActionButton } from "@mitodl/smoot-design"
77
import { EditableCaption } from "../shared/EditableCaption"
8+
import { isVideoUrl } from "./lib"
89

910
const StyledNodeViewWrapper = styled(NodeViewWrapper, {
1011
shouldForwardProp: (prop) =>
@@ -123,7 +124,16 @@ const MediaContainer = styled.div(({ theme }) => ({
123124
display: "block",
124125
},
125126

126-
".layout-full & iframe": {
127+
video: {
128+
width: "100%",
129+
height: "100%",
130+
borderRadius: "6px",
131+
display: "block",
132+
objectFit: "contain",
133+
backgroundColor: "#000",
134+
},
135+
136+
".layout-full & iframe, .layout-full & video": {
127137
borderRadius: 0,
128138
},
129139
".ProseMirror-selectednode .layout-wide &": {
@@ -216,13 +226,14 @@ export const MediaEmbedNodeView = ({
216226
)}
217227

218228
<MediaContainer>
219-
<iframe
220-
src={src}
221-
frameBorder="0"
222-
allowFullScreen
223-
title={caption}
224-
inert={editable}
225-
/>
229+
{isVideoUrl(src) ? (
230+
<video src={src} controls title={caption}>
231+
<track kind="captions" />
232+
Your browser does not support the video tag.
233+
</video>
234+
) : (
235+
<iframe src={src} frameBorder="0" allowFullScreen title={caption} />
236+
)}
226237
</MediaContainer>
227238

228239
<EditableCaption

frontends/main/src/page-components/TiptapEditor/extensions/node/MediaEmbed/MediaEmbedViewer.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react"
22
import styled from "@emotion/styled"
33
import { EditableCaption } from "../shared/EditableCaption"
4+
import { isVideoUrl } from "./lib"
45

56
const StyledWrapper = styled.div({
67
position: "relative",
@@ -35,6 +36,15 @@ const MediaContainer = styled.div({
3536
borderRadius: "6px",
3637
display: "block",
3738
},
39+
40+
video: {
41+
width: "100%",
42+
height: "100%",
43+
borderRadius: "6px",
44+
display: "block",
45+
objectFit: "contain",
46+
backgroundColor: "#000",
47+
},
3848
})
3949

4050
interface MediaEmbedNode {
@@ -53,7 +63,14 @@ export const MediaEmbedViewer = ({ node }: { node?: MediaEmbedNode }) => {
5363
return (
5464
<StyledWrapper className={`layout-${layout}`}>
5565
<MediaContainer>
56-
<iframe src={src} frameBorder="0" allowFullScreen title={caption} />
66+
{isVideoUrl(src) ? (
67+
<video src={src} controls title={caption}>
68+
<track kind="captions" />
69+
Your browser does not support the video tag.
70+
</video>
71+
) : (
72+
<iframe src={src} frameBorder="0" allowFullScreen title={caption} />
73+
)}
5774
</MediaContainer>
5875

5976
<EditableCaption

frontends/main/src/page-components/TiptapEditor/extensions/node/MediaEmbed/lib.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
export function isVideoUrl(url: string): boolean {
2+
try {
3+
const parsed = new URL(url)
4+
return parsed.pathname.toLowerCase().endsWith(".mp4")
5+
} catch {
6+
return false
7+
}
8+
}
9+
110
export function convertToEmbedUrl(url: string): string | null {
211
let parsed: URL
312

@@ -9,6 +18,14 @@ export function convertToEmbedUrl(url: string): string | null {
918

1019
const hostname = parsed.hostname.replace("www.", "")
1120

21+
// --- MIT LEARN MP4 VIDEOS ---
22+
if (
23+
hostname === "learn.mit.edu" &&
24+
parsed.pathname.toLowerCase().endsWith(".mp4")
25+
) {
26+
return url // Return the URL as-is for video element
27+
}
28+
1229
// --- YOUTUBE WATCH ---
1330
if (hostname === "youtube.com" && parsed.pathname === "/watch") {
1431
const videoId = parsed.searchParams.get("v")

0 commit comments

Comments
 (0)