fix(media): add inline podcast player, video buffering track, click-outside speed menu and safe product edit trim
Deploy Canina / deploy (push) Has been cancelled
Deploy Canina / deploy (push) Has been cancelled
This commit is contained in:
1 parent
95d79518e7
commit
36e382cf16
17 files changed
+12496
-11618
No files matched your search
@@ -39,11 +39,13 @@ const PLAYBACK_RATES = [0.5, 1, 1.25, 1.5, 1.75, 2, 2.5];
|
||||
export default function VideoModalPlayer({ isOpen, onClose, video }: VideoModalPlayerProps) {
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const rateMenuRef = useRef<HTMLDivElement>(null);
|
||||
const controlsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const [isPlaying, setIsPlaying] = useState(false);
|
||||
const [currentTime, setCurrentTime] = useState(0);
|
||||
const [duration, setDuration] = useState(0);
|
||||
const [bufferedEnd, setBufferedEnd] = useState(0);
|
||||
const [volume, setVolume] = useState(1);
|
||||
const [isMuted, setIsMuted] = useState(false);
|
||||
const [playbackRate, setPlaybackRate] = useState(1);
|
||||
@@ -54,6 +56,21 @@ export default function VideoModalPlayer({ isOpen, onClose, video }: VideoModalP
|
||||
const [isExpandedDesc, setIsExpandedDesc] = useState(false);
|
||||
const [isCopied, setIsCopied] = useState(false);
|
||||
|
||||
// Close rate menu when clicking outside
|
||||
useEffect(() => {
|
||||
function handleClickOutside(e: MouseEvent) {
|
||||
if (rateMenuRef.current && !rateMenuRef.current.contains(e.target as Node)) {
|
||||
setShowRateMenu(false);
|
||||
}
|
||||
}
|
||||
if (showRateMenu) {
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
}
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
};
|
||||
}, [showRateMenu]);
|
||||
|
||||
// Reset states on open/close
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
@@ -61,12 +78,30 @@ export default function VideoModalPlayer({ isOpen, onClose, video }: VideoModalP
|
||||
setShowControls(true);
|
||||
setIsExpandedDesc(false);
|
||||
setShowRateMenu(false);
|
||||
setBufferedEnd(0);
|
||||
} else {
|
||||
setIsPlaying(false);
|
||||
setCurrentTime(0);
|
||||
setBufferedEnd(0);
|
||||
}
|
||||
}, [isOpen, video]);
|
||||
|
||||
// Update buffered track
|
||||
const updateBuffer = useCallback(() => {
|
||||
if (videoRef.current && videoRef.current.buffered.length > 0) {
|
||||
const current = videoRef.current.currentTime;
|
||||
for (let i = 0; i < videoRef.current.buffered.length; i++) {
|
||||
if (
|
||||
videoRef.current.buffered.start(i) <= current &&
|
||||
videoRef.current.buffered.end(i) >= current
|
||||
) {
|
||||
setBufferedEnd(videoRef.current.buffered.end(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Handle auto-hide timer for controls
|
||||
const resetControlsTimer = useCallback(() => {
|
||||
setShowControls(true);
|
||||
@@ -214,6 +249,7 @@ export default function VideoModalPlayer({ isOpen, onClose, video }: VideoModalP
|
||||
|
||||
const isIframe = video.videoUrl?.includes("<iframe");
|
||||
const progressPercent = duration > 0 ? (currentTime / duration) * 100 : 0;
|
||||
const bufferedPercent = duration > 0 ? (bufferedEnd / duration) * 100 : 0;
|
||||
const volumePercent = isMuted ? 0 : volume * 100;
|
||||
|
||||
return (
|
||||
@@ -270,11 +306,16 @@ export default function VideoModalPlayer({ isOpen, onClose, video }: VideoModalP
|
||||
onPlay={() => setIsPlaying(true)}
|
||||
onPause={() => setIsPlaying(false)}
|
||||
onTimeUpdate={() => {
|
||||
if (videoRef.current) setCurrentTime(videoRef.current.currentTime);
|
||||
if (videoRef.current) {
|
||||
setCurrentTime(videoRef.current.currentTime);
|
||||
updateBuffer();
|
||||
}
|
||||
}}
|
||||
onProgress={updateBuffer}
|
||||
onLoadedMetadata={() => {
|
||||
if (videoRef.current) setDuration(videoRef.current.duration);
|
||||
setIsBuffering(false);
|
||||
updateBuffer();
|
||||
}}
|
||||
onWaiting={() => setIsBuffering(true)}
|
||||
onPlaying={() => setIsBuffering(false)}
|
||||
@@ -372,16 +413,22 @@ export default function VideoModalPlayer({ isOpen, onClose, video }: VideoModalP
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Progress / Seek Bar with filled progress track */}
|
||||
{/* Progress / Seek Bar with filled progress & buffer tracks */}
|
||||
<div className="flex items-center gap-3 dir-ltr" dir="ltr">
|
||||
<span className="text-[11px] font-mono font-bold text-white/70 w-10 text-right">
|
||||
{formatTime(currentTime)}
|
||||
</span>
|
||||
<div className="relative flex-1 flex items-center h-4">
|
||||
{/* Background Track */}
|
||||
{/* Background & Buffer & Progress Track */}
|
||||
<div className="absolute inset-x-0 h-1.5 bg-white/20 rounded-lg overflow-hidden pointer-events-none">
|
||||
{/* Buffered bar */}
|
||||
<div
|
||||
className="h-full bg-canina-blue transition-all"
|
||||
className="h-full bg-white/35 transition-all duration-300"
|
||||
style={{ width: `${bufferedPercent}%` }}
|
||||
/>
|
||||
{/* Played progress bar */}
|
||||
<div
|
||||
className="h-full bg-canina-blue transition-all -mt-1.5"
|
||||
style={{ width: `${progressPercent}%` }}
|
||||
/>
|
||||
</div>
|
||||
@@ -477,8 +524,8 @@ export default function VideoModalPlayer({ isOpen, onClose, video }: VideoModalP
|
||||
|
||||
{/* Right Controls (Speed Menu & Fullscreen) */}
|
||||
<div className="flex items-center gap-2">
|
||||
{/* Playback Rate Popup Menu */}
|
||||
<div className="relative">
|
||||
{/* Playback Rate Popup Menu with click-outside */}
|
||||
<div className="relative" ref={rateMenuRef}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowRateMenu(!showRateMenu)}
|
||||
|
||||
Reference in new issue
Block a user