feat(player): plain crossfade between covers
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
- dropped the SVG turbulence/displacement filter entirely - the previous sleeve now simply dissolves over the next one, 0.55s ease - cover swap still waits for the new image to load
This commit is contained in:
1 parent
f20578a552
commit
4b67c94494
2 files changed
+12
-86
No files matched your search
@@ -124,24 +124,15 @@
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
// Both layers melt under the same turbulence filter while the old
|
||||
// sleeve fades out over the new one.
|
||||
&.is-melting {
|
||||
filter: url(#music-liquid-filter);
|
||||
|
||||
img {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
}
|
||||
|
||||
// The old sleeve layers over the new one and simply fades away.
|
||||
&-prev {
|
||||
z-index: 2;
|
||||
animation: cover-melt-out 0.8s ease forwards;
|
||||
animation: cover-fade-out 0.55s ease forwards;
|
||||
}
|
||||
|
||||
&-current {
|
||||
z-index: 1;
|
||||
animation: cover-melt-in 0.8s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
animation: cover-fade-in 0.55s ease;
|
||||
}
|
||||
|
||||
> .material-symbols-rounded {
|
||||
@@ -150,12 +141,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
&-liquid {
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
&-meta {
|
||||
width: min(560px, 100%);
|
||||
margin-top: clamp(1.2rem, 3vh, 2rem);
|
||||
@@ -666,18 +651,16 @@ html.is-macos .music-player-chrome {
|
||||
}
|
||||
|
||||
|
||||
@keyframes cover-melt-in {
|
||||
@keyframes cover-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(1.015);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes cover-melt-out {
|
||||
@keyframes cover-fade-out {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@@ -123,20 +123,16 @@ const QueueRow = ({
|
||||
</div>
|
||||
);
|
||||
|
||||
const MELT_MS = 800;
|
||||
const COVER_FADE_MS = 600;
|
||||
|
||||
/**
|
||||
* Sleeve that melts into the next track: the previous cover stays on top while
|
||||
* a turbulence + displacement filter ripples both layers, then fades away.
|
||||
* Sleeve that crossfades into the next track: the previous cover stays on top
|
||||
* while the next one loads, then simply dissolves over it.
|
||||
*/
|
||||
const LiquidCover = ({ src, alt }: { src?: string; alt: string }) => {
|
||||
const CoverArt = ({ src, alt }: { src?: string; alt: string }) => {
|
||||
const [current, setCurrent] = useState<string | undefined>(src);
|
||||
const [previous, setPrevious] = useState<string | undefined>();
|
||||
const [melting, setMelting] = useState(false);
|
||||
const currentRef = useRef<string | undefined>(src);
|
||||
const turbRef = useRef<SVGFETurbulenceElement | null>(null);
|
||||
const dispRef = useRef<SVGFEDisplacementMapElement | null>(null);
|
||||
const rafRef = useRef(0);
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -150,33 +146,10 @@ const LiquidCover = ({ src, alt }: { src?: string; alt: string }) => {
|
||||
setPrevious(currentRef.current);
|
||||
currentRef.current = src;
|
||||
setCurrent(src);
|
||||
setMelting(true);
|
||||
|
||||
const started = performance.now();
|
||||
const step = (now: number) => {
|
||||
const t = Math.min((now - started) / MELT_MS, 1);
|
||||
const wave = Math.sin(Math.PI * t);
|
||||
dispRef.current?.setAttribute(
|
||||
"scale",
|
||||
String(Math.round(wave * 10)),
|
||||
);
|
||||
turbRef.current?.setAttribute(
|
||||
"baseFrequency",
|
||||
String(0.005 + wave * 0.003),
|
||||
);
|
||||
if (t < 1) {
|
||||
rafRef.current = requestAnimationFrame(step);
|
||||
} else {
|
||||
dispRef.current?.setAttribute("scale", "0");
|
||||
setMelting(false);
|
||||
}
|
||||
};
|
||||
cancelAnimationFrame(rafRef.current);
|
||||
rafRef.current = requestAnimationFrame(step);
|
||||
if (timerRef.current) clearTimeout(timerRef.current);
|
||||
timerRef.current = setTimeout(
|
||||
() => setPrevious(undefined),
|
||||
MELT_MS + 60,
|
||||
COVER_FADE_MS + 40,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -188,49 +161,19 @@ const LiquidCover = ({ src, alt }: { src?: string; alt: string }) => {
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
cancelAnimationFrame(rafRef.current);
|
||||
if (timerRef.current) clearTimeout(timerRef.current);
|
||||
};
|
||||
}, [src]);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
cancelAnimationFrame(rafRef.current);
|
||||
if (timerRef.current) clearTimeout(timerRef.current);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={`music-player-art${melting ? " is-melting" : ""}`}>
|
||||
<svg className="music-player-liquid" aria-hidden="true">
|
||||
<defs>
|
||||
<filter
|
||||
id="music-liquid-filter"
|
||||
x="-25%"
|
||||
y="-25%"
|
||||
width="150%"
|
||||
height="150%"
|
||||
>
|
||||
<feTurbulence
|
||||
ref={turbRef}
|
||||
type="fractalNoise"
|
||||
baseFrequency="0.005"
|
||||
numOctaves="1"
|
||||
seed="4"
|
||||
result="noise"
|
||||
/>
|
||||
<feDisplacementMap
|
||||
ref={dispRef}
|
||||
in="SourceGraphic"
|
||||
in2="noise"
|
||||
scale="0"
|
||||
xChannelSelector="R"
|
||||
yChannelSelector="G"
|
||||
/>
|
||||
</filter>
|
||||
</defs>
|
||||
</svg>
|
||||
<div className="music-player-art">
|
||||
{previous && (
|
||||
<img
|
||||
key={previous}
|
||||
@@ -403,7 +346,7 @@ function AudioPlayerRoute() {
|
||||
<div className="music-player-stage">
|
||||
<div className="music-player-row">
|
||||
<div className="music-player-main">
|
||||
<LiquidCover
|
||||
<CoverArt
|
||||
src={imageUrl}
|
||||
alt={item?.Name ?? "Обложка"}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user