fix(performance): eliminate device thermal throttling and remove expand icon from trendy bento
This commit is contained in:
@@ -288,15 +288,47 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Continuous Autoplay Muted Loop (Plays all the time on phones and desktop without requiring hover)
|
||||
// Continuous Autoplay Muted Loop when visible in viewport
|
||||
// Pauses automatically when scrolled out of view or tab is hidden to save GPU/battery and eliminate device heating
|
||||
useEffect(() => {
|
||||
if (item.mediaType === 'video' && videoRef.current) {
|
||||
const video = videoRef.current;
|
||||
video.muted = true;
|
||||
video.defaultMuted = true;
|
||||
video.playsInline = true;
|
||||
video.play().catch(() => {});
|
||||
}
|
||||
if (item.mediaType !== 'video') return;
|
||||
const video = videoRef.current;
|
||||
if (!video) return;
|
||||
|
||||
video.muted = true;
|
||||
video.defaultMuted = true;
|
||||
video.playsInline = true;
|
||||
|
||||
let isIntersecting = false;
|
||||
|
||||
const updatePlayState = () => {
|
||||
if (isIntersecting && !document.hidden) {
|
||||
video.play().catch(() => {});
|
||||
} else {
|
||||
video.pause();
|
||||
}
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
isIntersecting = entry.isIntersecting;
|
||||
updatePlayState();
|
||||
},
|
||||
{ threshold: 0.05 }
|
||||
);
|
||||
|
||||
observer.observe(video);
|
||||
|
||||
const handleVisibility = () => {
|
||||
updatePlayState();
|
||||
};
|
||||
document.addEventListener('visibilitychange', handleVisibility);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
document.removeEventListener('visibilitychange', handleVisibility);
|
||||
video.pause();
|
||||
};
|
||||
}, [item.mediaType]);
|
||||
|
||||
// When unhovered, reset slider smoothly to 50%
|
||||
|
||||
Reference in New Issue
Block a user