diff --git a/src/components/PhotoFrame.tsx b/src/components/PhotoFrame.tsx index c94e62857..662706020 100644 --- a/src/components/PhotoFrame.tsx +++ b/src/components/PhotoFrame.tsx @@ -101,6 +101,7 @@ const PhotoFrame = ({ const filteredDataRef = useRef([]); const filteredData = filteredDataRef?.current ?? []; const router = useRouter(); + const [livePhotoLoaded, setLivePhotoLoaded] = useState(false); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Shift') { @@ -241,6 +242,28 @@ const PhotoFrame = ({ } }, [open]); + useEffect(() => { + const livePhotoVideo: HTMLVideoElement = + document.querySelector('video'); + const livePhotoBtn: HTMLButtonElement = + document.querySelector('.live-photo-btn'); + if (livePhotoVideo && livePhotoBtn) { + livePhotoBtn.addEventListener('mouseout', function () { + livePhotoVideo.pause(); + }); + livePhotoBtn.addEventListener('mouseover', function () { + livePhotoVideo.play().catch(() => { + livePhotoVideo.pause(); + }); + }); + livePhotoBtn.addEventListener('click', function () { + livePhotoVideo.play().catch(() => { + livePhotoVideo.pause(); + }); + }); + } + }, [livePhotoLoaded]); + const updateURL = (index: number) => (url: string) => { files[index] = { ...files[index], @@ -301,11 +324,34 @@ const PhotoFrame = ({ } else if (files[index].metadata.fileType === FILE_TYPE.LIVE_PHOTO) { if (await isPlaybackPossible(url)) { files[index].html = ` - - `; +
+ + +
+ `; + setLivePhotoLoaded(true); + } else { + files[index].html = ` +
+ +
+ ${constants.VIDEO_PLAYBACK_FAILED_DOWNLOAD_INSTEAD} + Download +
+
+ `; } } else { files[index].src = url; @@ -462,6 +508,9 @@ const PhotoFrame = ({ } galleryContext.files.set(item.id, url); } + if (item.metadata.fileType === FILE_TYPE.LIVE_PHOTO) { + setLivePhotoLoaded(false); + } await updateSrcURL(item.dataIndex, url); item.html = files[item.dataIndex].html; item.src = files[item.dataIndex].src; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 031791c39..b4ea3cd43 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -69,6 +69,25 @@ const GlobalStyles = createGlobalStyle` height: 100%; } + .live-photo-container{ + width: 100%; + height: 100%; + position: relative; + } + + .live-photo-container > button { + position: absolute; + bottom: 10vh; + left: calc(50% - 20px); + height: 40px; + width: 80px; + background: #d7d7d7; + outline: none; + border: none; + border-radius: 10%; + z-index: 10; + } + .video-loading { width: 100%; height: 100%;