Skip to content

Commit 82c4f41

Browse files
committed
Update video streaming URLs and improve MP4 header handling
Removed hardcoded localhost URLs for video streaming in the frontend to ensure compatibility in different environments. Refined MP4 response headers in the backend to improve browser compatibility, including preserving the correct content type and adding metadata-related headers for better handling of files with the moov atom at the end.
1 parent 1332b8f commit 82c4f41

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

frontend/src/pages/UnreviewedPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ const UnreviewedPage: React.FC = () => {
273273
</Flex>
274274
) : (
275275
<ReactPlayer
276-
url={`http://localhost:3000/api/videos/${currentVideo.id}/stream`}
276+
url={`/api/videos/${currentVideo.id}/stream`}
277277
controls
278278
width="100%"
279279
height="auto"

frontend/src/pages/VideoDetailPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ const VideoDetailPage: React.FC = () => {
298298
borderColor={borderColor}
299299
>
300300
<ReactPlayer
301-
url={`http://localhost:3000/api/videos/${video.id}/stream`}
301+
url={`/api/videos/${video.id}/stream`}
302302
controls
303303
width="100%"
304304
height="auto"

src/routes/video.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,9 @@ async fn stream_video(
251251
// This helps with MP4 files that have their metadata at the end
252252
additional_headers.push((header::ACCEPT_RANGES, "bytes".to_string()));
253253

254-
// If moov atom is not at the beginning, use a different approach
254+
// If moov atom is not at the beginning, add headers to help browsers handle it
255255
if !has_moov_at_beginning {
256-
// Use application/octet-stream content type to force download before playing
257-
// This ensures the browser has the complete file before attempting to parse metadata
258-
content_type = "application/octet-stream".to_string();
259-
256+
// Keep the content type as video/mp4 to ensure proper decoding in browsers
260257
// Add Cache-Control: no-store to prevent caching of problematic MP4
261258
additional_headers.push((header::CACHE_CONTROL, "no-store".to_string()));
262259

@@ -268,6 +265,10 @@ async fn stream_video(
268265
if let Some(duration) = get_mp4_duration(&path) {
269266
additional_headers.push(("X-Content-Duration".parse().unwrap(), duration.to_string()));
270267
}
268+
269+
// Add a header to indicate that the moov atom is at the end
270+
// This can help some browsers handle the file better
271+
additional_headers.push(("X-MP4-Has-Moov-At-Beginning".parse().unwrap(), "false".to_string()));
271272
} else {
272273
// For MP4 files with moov atom at the beginning, just add inline content disposition
273274
additional_headers.push((header::CONTENT_DISPOSITION, "inline".to_string()));

0 commit comments

Comments
 (0)