feat(player): liquid crossfade when the cover changes
Continuous Integration / build_web (push) Failing after 1s
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 1s
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
- the previous sleeve stays while the next one loads, then both melt under an SVG turbulence/displacement filter during a soft crossfade with a light zoom - kept subtle: small displacement, slow single-octave noise and an 0.8s transition
This commit is contained in:
1 parent
ae1e81d8d8
commit
f20578a552
2 files changed
+186
-14
No files matched your search
@@ -105,6 +105,7 @@
|
||||
|
||||
|
||||
&-art {
|
||||
position: relative;
|
||||
width: clamp(200px, min(48vh, 34vw), 430px);
|
||||
aspect-ratio: 1;
|
||||
overflow: hidden;
|
||||
@@ -115,18 +116,46 @@
|
||||
place-items: center;
|
||||
|
||||
img {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
&-prev {
|
||||
z-index: 2;
|
||||
animation: cover-melt-out 0.8s ease forwards;
|
||||
}
|
||||
|
||||
&-current {
|
||||
z-index: 1;
|
||||
animation: cover-melt-in 0.8s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
> .material-symbols-rounded {
|
||||
font-size: 5rem;
|
||||
color: rgb(255 255 255 / 0.4);
|
||||
}
|
||||
}
|
||||
|
||||
&-liquid {
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
&-meta {
|
||||
width: min(560px, 100%);
|
||||
margin-top: clamp(1.2rem, 3vh, 2rem);
|
||||
@@ -636,3 +665,25 @@ html.is-macos .music-player-chrome {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@keyframes cover-melt-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(1.015);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes cover-melt-out {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import CastButton from "@/components/buttons/castButton";
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import LyricsPanel, {
|
||||
@@ -123,6 +123,136 @@ const QueueRow = ({
|
||||
</div>
|
||||
);
|
||||
|
||||
const MELT_MS = 800;
|
||||
|
||||
/**
|
||||
* Sleeve that melts into the next track: the previous cover stays on top while
|
||||
* a turbulence + displacement filter ripples both layers, then fades away.
|
||||
*/
|
||||
const LiquidCover = ({ 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(() => {
|
||||
if (!src || src === currentRef.current) return;
|
||||
let cancelled = false;
|
||||
let begun = false;
|
||||
|
||||
const start = () => {
|
||||
if (cancelled || begun) return;
|
||||
begun = true;
|
||||
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,
|
||||
);
|
||||
};
|
||||
|
||||
const image = new Image();
|
||||
image.onload = start;
|
||||
image.onerror = start;
|
||||
image.src = src;
|
||||
if (image.complete && image.naturalWidth > 0) start();
|
||||
|
||||
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>
|
||||
{previous && (
|
||||
<img
|
||||
key={previous}
|
||||
className="music-player-art-prev"
|
||||
src={previous}
|
||||
alt=""
|
||||
/>
|
||||
)}
|
||||
{current ? (
|
||||
<img
|
||||
key={current}
|
||||
className="music-player-art-current"
|
||||
src={current}
|
||||
alt={alt}
|
||||
/>
|
||||
) : (
|
||||
<span className="material-symbols-rounded">music_note</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function AudioPlayerRoute() {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
@@ -273,19 +403,10 @@ function AudioPlayerRoute() {
|
||||
<div className="music-player-stage">
|
||||
<div className="music-player-row">
|
||||
<div className="music-player-main">
|
||||
<motion.div
|
||||
key={item?.Id}
|
||||
className="music-player-art"
|
||||
initial={{ opacity: 0, scale: 0.98 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
transition={{ duration: 0.3, ease: "easeOut" }}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<img alt={item?.Name ?? "Обложка"} src={imageUrl} />
|
||||
) : (
|
||||
<span className="material-symbols-rounded">music_note</span>
|
||||
)}
|
||||
</motion.div>
|
||||
<LiquidCover
|
||||
src={imageUrl}
|
||||
alt={item?.Name ?? "Обложка"}
|
||||
/>
|
||||
|
||||
<div className="music-player-meta">
|
||||
<h1 className="music-player-title">{item?.Name}</h1>
|
||||
|
||||
Reference in new issue
Block a user