Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

Refactor: Rename VideoPlayer to MediaPlayer and add audio support

Cursor Agent44c2a3270e1b
diff --git a/components/view/viewer/video-player.tsx b/components/view/viewer/video-player.tsx
index 0b718edc..8085079e 100644
--- a/components/view/viewer/video-player.tsx
+++ b/components/view/viewer/video-player.tsx
@@ -8,19 +8,19 @@ import {
import { cn } from "@/lib/utils";
-interface VideoPlayerProps {
- videoSrc: string;
+interface MediaPlayerProps {
+ mediaSrc: string;
onError?: (error: Error) => void;
controls?: boolean;
className?: string;
preventDownload?: boolean;
}
-export const VideoPlayer = memo(
- forwardRef<HTMLVideoElement, VideoPlayerProps>(
+export const MediaPlayer = memo(
+ forwardRef<HTMLVideoElement, MediaPlayerProps>(
(
{
- videoSrc,
+ mediaSrc,
onError,
controls = true,
className = "",
@@ -37,8 +37,8 @@ export const VideoPlayer = memo(
if (!video) return;
const handleError = (e: ErrorEvent) => {
- console.error("Video playback error:", e);
- onError?.(new Error("Failed to play video"));
+ console.error("Media playback error:", e);
+ onError?.(new Error("Failed to play media"));
};
video.addEventListener("error", handleError);
@@ -61,14 +61,17 @@ export const VideoPlayer = memo(
onContextMenu={
preventDownload ? (e) => e.preventDefault() : undefined
}
- src={videoSrc}
+ src={mediaSrc}
>
- <source src={videoSrc} type="video/mp4" />
- Your browser does not support the video tag.
+ <source src={mediaSrc} />
+ Your browser does not support the media tag.
</video>
);
},
),
);
-VideoPlayer.displayName = "VideoPlayer";
+MediaPlayer.displayName = "MediaPlayer";
+
+// Keep the old VideoPlayer export for backward compatibility
+export const VideoPlayer = MediaPlayer;
diff --git a/components/view/viewer/video-viewer.tsx b/components/view/viewer/video-viewer.tsx
index a2a9be10..04184b26 100644
--- a/components/view/viewer/video-viewer.tsx
+++ b/components/view/viewer/video-viewer.tsx
@@ -7,7 +7,7 @@ import { cn } from "@/lib/utils";
import { ScreenProtector } from "../ScreenProtection";
import Nav, { TNavData } from "../nav";
-import { VideoPlayer } from "./video-player";
+import { MediaPlayer } from "./video-player";
export default function VideoViewer({
file,
@@ -109,9 +109,9 @@ export default function VideoViewer({
)}
>
<div className="relative flex h-full w-full items-center justify-center">
- <VideoPlayer
+ <MediaPlayer
ref={videoRef}
- videoSrc={file}
+ mediaSrc={file}
onError={handleVideoError}
preventDownload={!allowDownload}
/>
diff --git a/lib/api/documents/process-document.ts b/lib/api/documents/process-document.ts
index ba64f6a5..f5860132 100644
--- a/lib/api/documents/process-document.ts
+++ b/lib/api/documents/process-document.ts
@@ -171,7 +171,7 @@ export const processDocument = async ({
);
}
- if (type === "video" && contentType !== "video/mp4") {
+ if (type === "video" && contentType !== "video/mp4" && contentType?.startsWith("video/")) {
await processVideo.trigger(
{
videoUrl: key,
diff --git a/lib/constants.ts b/lib/constants.ts
index 2a7fca97..b4fa9f48 100644
--- a/lib/constants.ts
+++ b/lib/constants.ts
@@ -92,6 +92,8 @@ export const SUPPORTED_DOCUMENT_MIME_TYPES = [
"video/x-msvideo", // .avi
"video/webm", // .webm
"video/ogg", // .ogg
+ "audio/mp4", // .m4a
+ "audio/mpeg", // .mp3
"application/vnd.google-earth.kml+xml", // .kml
"application/vnd.google-earth.kmz", // .kmz
"application/vnd.ms-outlook", // .msg
@@ -138,6 +140,8 @@ export const FULL_PLAN_ACCEPTED_FILE_TYPES = {
"video/x-msvideo": [], // ".avi"
"video/webm": [], // ".webm"
"video/ogg": [], // ".ogg"
+ "audio/mp4": [], // ".m4a"
+ "audio/mpeg": [], // ".mp3"
"application/vnd.google-earth.kml+xml": [".kml"], // ".kml"
"application/vnd.google-earth.kmz": [".kmz"], // ".kmz"
"application/vnd.ms-outlook": [".msg"], // ".msg"
diff --git a/lib/utils/get-content-type.ts b/lib/utils/get-content-type.ts
index 0c1a354a..c80cdd8b 100644
--- a/lib/utils/get-content-type.ts
+++ b/lib/utils/get-content-type.ts
@@ -34,6 +34,8 @@ export function getSupportedContentType(contentType: string): string | null {
case "video/x-msvideo":
case "video/webm":
case "video/ogg":
+ case "audio/mp4":
+ case "audio/mpeg":
return "video";
case "application/vnd.google-earth.kml+xml":
case "application/vnd.google-earth.kmz":
@@ -98,6 +100,10 @@ export function getExtensionFromContentType(
return "webm";
case "video/ogg":
return "ogg";
+ case "audio/mp4":
+ return "m4a";
+ case "audio/mpeg":
+ return "mp3";
case "application/vnd.google-earth.kml+xml":
return "kml";
case "application/vnd.google-earth.kmz":
diff --git a/lib/utils/get-file-icon.tsx b/lib/utils/get-file-icon.tsx
index d8023187..187236ed 100644
--- a/lib/utils/get-file-icon.tsx
+++ b/lib/utils/get-file-icon.tsx
@@ -56,6 +56,8 @@ export function fileIcon({
case "video/ogg":
case "video/x-msvideo":
case "video":
+ case "audio/mp4":
+ case "audio/mpeg":
return <VideoIcon className={className} isLight={isLight} />;
case "application/vnd.google-earth.kml+xml":
case "application/vnd.google-earth.kmz":
diff --git a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
index 4eba34aa..5e6f57fe 100644
--- a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
@@ -133,7 +133,7 @@ export default async function handle(
);
}
- if (type === "video" && contentType !== "video/mp4") {
+ if (type === "video" && contentType !== "video/mp4" && contentType.startsWith("video/")) {
await processVideo.trigger(
{
videoUrl: url,