Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: iOS safari playback issues

Richie McIlroyb530b1f444f7
diff --git a/apps/web/app/s/[videoId]/_components/VideoPlayer.tsx b/apps/web/app/s/[videoId]/_components/VideoPlayer.tsx
index e58ce9111..beff2417f 100644
--- a/apps/web/app/s/[videoId]/_components/VideoPlayer.tsx
+++ b/apps/web/app/s/[videoId]/_components/VideoPlayer.tsx
@@ -18,12 +18,15 @@ export const VideoPlayer = memo(
useImperativeHandle(ref, () => videoRef.current as HTMLVideoElement);
+ const isIOS = () =>
+ /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
+
const initializeHls = (
src: string,
media: HTMLMediaElement,
hlsInstance: React.MutableRefObject<Hls | null>
) => {
- if (Hls.isSupported()) {
+ if (Hls.isSupported() && !isIOS()) {
const hls = new Hls({ progressive: true });
hls.on(Hls.Events.ERROR, (event, data) => {
console.error("HLS error:", data);
@@ -36,7 +39,6 @@ export const VideoPlayer = memo(
hls.recoverMediaError();
break;
default:
- initializeFallback(src, media);
break;
}
}
@@ -46,17 +48,18 @@ export const VideoPlayer = memo(
hls.loadSource(src);
hls.attachMedia(media);
} else {
- initializeFallback(src, media);
+ media.src = src;
}
};
- const initializeFallback = (src: string, media: HTMLMediaElement) => {
- media.src = src;
- };
-
useEffect(() => {
if (!videoRef.current) return;
- initializeHls(videoSrc, videoRef.current, videoHlsInstance);
+
+ if (isIOS()) {
+ videoRef.current.src = videoSrc;
+ } else {
+ initializeHls(videoSrc, videoRef.current, videoHlsInstance);
+ }
return () => {
videoHlsInstance.current?.destroy();