Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Improve video playback experience on web (#500)
Ameer Al Ashhab5cf42414f43c
diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsxindex 7acdeafd3..1db4a7dba 100644--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx@@ -1,3 +1,4 @@+import { UpgradeModal } from "@/components/UpgradeModal";import { apiClient } from "@/utils/web-api";import { userSelectProps } from "@cap/database/auth/session";import { comments as commentsSchema, videos } from "@cap/database/schema";@@ -5,6 +6,7 @@ import { clientEnv, NODE_ENV } from "@cap/env";import { Logo, LogoSpinner } from "@cap/ui";import { isUserOnProPlan, S3_BUCKET_URL } from "@cap/utils";import clsx from "clsx";+import { AnimatePresence, motion } from "framer-motion";import {Maximize,MessageSquare,@@ -25,7 +27,6 @@ import { Tooltip } from "react-tooltip";import { fromVtt, Subtitle } from "subtitles-parser-vtt";import { MP4VideoPlayer } from "./MP4VideoPlayer";import { VideoPlayer } from "./VideoPlayer";-import { UpgradeModal } from "@/components/UpgradeModal";declare global {interface Window {@@ -74,6 +75,7 @@ export const ShareVideo = forwardRef<const [isTranscriptionProcessing, setIsTranscriptionProcessing] =useState(false);const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);+ const [tempOverlayVisible, setTempOverlayVisible] = useState(false);// Scrubbing preview statesconst [showPreview, setShowPreview] = useState(false);@@ -218,6 +220,39 @@ export const ShareVideo = forwardRef<}}, [videoMetadataLoaded]);+ useEffect(() => {+ const handleShortcuts = (e: KeyboardEvent) => {+ // Skip handling if user is typing in form controls+ const target = e.target as HTMLElement;+ const isFormElement =+ target.tagName === "INPUT" ||+ target.tagName === "TEXTAREA" ||+ target.tagName === "SELECT" ||+ target.isContentEditable ||+ target.getAttribute("role") === "textbox";++ // Only handle shortcuts if not typing in a form control+ if (!isFormElement && videoRef.current) {+ if (e.code === "Space") {+ e.preventDefault(); // Prevent page scrolling+ if (isPlaying) {+ videoRef.current.pause();+ setIsPlaying(false);+ } else {+ videoRef.current.play();+ setIsPlaying(true);+ }+ }+ }+ };++ window.addEventListener("keydown", handleShortcuts);++ return () => {+ window.removeEventListener("keydown", handleShortcuts);+ };+ }, [isPlaying, videoRef]);+useEffect(() => {const onVideoLoadedMetadata = () => {if (videoRef.current) {@@ -231,6 +266,16 @@ export const ShareVideo = forwardRef<setVideoMetadataLoaded(true);setVideoReadyToPlay(true);+ // Autoplay the video when it's ready on initial render+ setIsPlaying(true);+ if (videoRef.current) {+ videoRef.current.play().catch((error) => {+ console.error("Error auto-playing video:", error);+ // If autoplay fails (common on mobile), don't set isPlaying+ setIsPlaying(false);+ });+ }+// If the video is already playing (user clicked play before it was ready),// ensure it actually starts playing nowif (isPlaying && videoRef.current) {@@ -436,6 +481,20 @@ export const ShareVideo = forwardRef<};}, [seeking]);+ // Show overlay temporarily when play state changes+ useEffect(() => {+ // When video play state changes, show overlay temporarily+ setTempOverlayVisible(true);++ // Hide temporary overlay after 500ms+ const timer = setTimeout(() => {+ setTempOverlayVisible(false);+ }, 500);++ // Clean up timer on unmount or when isPlaying changes again+ return () => clearTimeout(timer);+ }, [isPlaying]);+// Set up a hidden video element for scrubbing previewsuseEffect(() => {// Only set up scrubbing video on large screens@@ -1071,7 +1130,10 @@ export const ShareVideo = forwardRef<{!isLoading && (<divclassName={`absolute inset-0 z-20 flex items-center justify-center bg-black bg-opacity-50 transition-opacity duration-300 ${- (overlayVisible || isHovering) && !forceHideControls+ ((overlayVisible || isHovering) &&+ !forceHideControls &&+ isPlaying) ||+ tempOverlayVisible? "opacity-100": "opacity-0"}`}@@ -1095,11 +1157,37 @@ export const ShareVideo = forwardRef<}}}>- {isPlaying ? (- <Pause className="w-auto h-10 text-white sm:h-12 md:h-14 hover:opacity-50" />- ) : (- <Play className="w-auto h-10 text-white sm:h-12 md:h-14 hover:opacity-50" />- )}+ <AnimatePresence initial={false} mode="popLayout">+ {isPlaying ? (+ <motion.div+ key="pause-button"+ className="flex relative z-30 justify-center items-center size-20"+ initial={{ opacity: 0, scale: 0 }}+ animate={{+ scale: 1,+ opacity: 1,+ }}+ style={{ transformOrigin: "center center" }}+ transition={{ duration: 0.4, ease: "easeOut" }}+ >+ <Pause className="w-auto h-10 text-white sm:h-12 md:h-14 hover:opacity-50" />+ </motion.div>+ ) : (+ <motion.div+ key="play-button"+ className="flex relative z-30 justify-center items-center size-20"+ initial={{ opacity: 0, scale: 0 }}+ animate={{+ scale: 1,+ opacity: 1,+ }}+ style={{ transformOrigin: "center center" }}+ transition={{ duration: 0.4, ease: "easeOut" }}+ >+ <Play className="w-auto h-10 text-white sm:h-12 md:h-14 hover:opacity-50" />+ </motion.div>+ )}+ </AnimatePresence></button></div>)}diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity.tsxindex ec7ab0a9f..5a1fcf018 100644--- a/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity.tsx@@ -4,6 +4,7 @@ import { getVideoAnalytics } from "@/actions/videos/get-analytics";import { CapCardAnalytics } from "@/app/dashboard/caps/components/CapCardAnalytics";import { userSelectProps } from "@cap/database/auth/session";import { comments as commentsSchema } from "@cap/database/schema";+import { Button } from "@cap/ui";import clsx from "clsx";import { AnimatePresence, motion } from "framer-motion";import { useEffect, useRef, useState } from "react";@@ -102,22 +103,16 @@ const CommentInput: React.FC<CommentInputProps> = ({onChange={(e) => setContent(e.target.value)}onKeyDown={handleKeyDown}placeholder={placeholder || "Leave a comment"}- className="w-full text-[15px] leading-[22px] text-gray-1 bg-transparent focus:outline-none"+ className="w-full text-[15px] leading-[22px] text-gray-12 bg-transparent focus:outline-none"/><div className="flex mt-2 space-x-2">- <button- onClick={() => handleSubmit()}- className="px-2 py-1.5 bg-blue-500 text-white text-xs font-medium rounded-full hover:bg-blue-600 focus:outline-none"- >+ <Button size="sm" variant="primary" onClick={() => handleSubmit()}>{buttonLabel}- </button>+ </Button>{showCancelButton && onCancel && (- <button- onClick={onCancel}- className="px-2 py-1.5 bg-gray-1 text-gray-700 text-xs font-medium rounded-full hover:bg-gray-200 focus:outline-none"- >+ <Button size="sm" variant="white" onClick={onCancel}>Cancel- </button>+ </Button>)}</div></div>