배경음악 기능 추가 및 예외 처리 수정
This commit is contained in:
1 parent
cf27da30b4
commit
a155a98767
12 files changed
+248
-66
No files matched your search
@@ -1,10 +1,87 @@
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getVideosList, deleteVideo } from '../../utils/api';
|
||||
import { VideoListItem } from '../../types/api';
|
||||
import SocialPostingModal from '../../components/SocialPostingModal';
|
||||
|
||||
const VideoPreviewCard: React.FC<{ src: string; className?: string }> = ({ src, className }) => {
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
const isPlayingRef = useRef(false);
|
||||
const pendingPlayRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const video = videoRef.current;
|
||||
if (!video) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
if (entry.isIntersecting) {
|
||||
video.preload = 'auto';
|
||||
} else {
|
||||
video.preload = 'none';
|
||||
}
|
||||
},
|
||||
{ threshold: 0.1 }
|
||||
);
|
||||
|
||||
observer.observe(video);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
const safePlay = useCallback((video: HTMLVideoElement) => {
|
||||
const playPromise = video.play();
|
||||
if (playPromise !== undefined) {
|
||||
playPromise
|
||||
.then(() => { isPlayingRef.current = true; })
|
||||
.catch((error) => {
|
||||
if (error.name !== 'AbortError') console.error(error);
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleCanPlay = useCallback(() => {
|
||||
if (!pendingPlayRef.current || !videoRef.current) return;
|
||||
pendingPlayRef.current = false;
|
||||
safePlay(videoRef.current);
|
||||
}, [safePlay]);
|
||||
|
||||
const handleMouseEnter = useCallback(() => {
|
||||
const video = videoRef.current;
|
||||
if (!video) return;
|
||||
if (video.readyState >= 3) {
|
||||
safePlay(video);
|
||||
} else {
|
||||
pendingPlayRef.current = true;
|
||||
}
|
||||
}, [safePlay]);
|
||||
|
||||
const handleMouseLeave = useCallback(() => {
|
||||
const video = videoRef.current;
|
||||
if (!video) return;
|
||||
pendingPlayRef.current = false;
|
||||
if (isPlayingRef.current) {
|
||||
video.pause();
|
||||
video.currentTime = 0;
|
||||
isPlayingRef.current = false;
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<video
|
||||
ref={videoRef}
|
||||
src={src}
|
||||
className={className}
|
||||
muted
|
||||
playsInline
|
||||
preload="none"
|
||||
onCanPlay={handleCanPlay}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
interface ADO2ContentsPageProps {
|
||||
onBack: () => void;
|
||||
onNavigate?: (item: string) => void;
|
||||
@@ -166,16 +243,9 @@ const ADO2ContentsPage: React.FC<ADO2ContentsPageProps> = ({ onBack, onNavigate
|
||||
{/* Video Thumbnail */}
|
||||
<div className="content-card-thumbnail">
|
||||
{video.result_movie_url ? (
|
||||
<video
|
||||
<VideoPreviewCard
|
||||
src={video.result_movie_url}
|
||||
className="content-video-preview"
|
||||
muted
|
||||
playsInline
|
||||
onMouseEnter={(e) => e.currentTarget.play()}
|
||||
onMouseLeave={(e) => {
|
||||
e.currentTarget.pause();
|
||||
e.currentTarget.currentTime = 0;
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div className="content-no-video">
|
||||
|
||||
Reference in new issue
Block a user