Merge branch 'music-fix-a'
This commit is contained in:
@@ -47,7 +47,15 @@ export default function AudioPlayer(props: {
|
|||||||
const [downloading, setDownloading] = useState(false);
|
const [downloading, setDownloading] = useState(false);
|
||||||
const { resolvedTheme } = useTheme();
|
const { resolvedTheme } = useTheme();
|
||||||
|
|
||||||
const { currentId, isPlaying, currentTime, toggle, seek, subscribeTime } = useMusicPlayer();
|
const {
|
||||||
|
currentId,
|
||||||
|
isPlaying,
|
||||||
|
currentTime,
|
||||||
|
duration: engineDuration,
|
||||||
|
toggle,
|
||||||
|
seek,
|
||||||
|
subscribeTime,
|
||||||
|
} = useMusicPlayer();
|
||||||
const isActive = currentId === props.id;
|
const isActive = currentId === props.id;
|
||||||
|
|
||||||
// Reach live values from the once-created wavesurfer callbacks.
|
// Reach live values from the once-created wavesurfer callbacks.
|
||||||
@@ -143,6 +151,9 @@ export default function AudioPlayer(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const playing = isActive && isPlaying;
|
const playing = isActive && isPlaying;
|
||||||
|
// The waveform is only a visual; playback is owned by the shared engine. Show
|
||||||
|
// its duration if the waveform hasn't decoded (slow/unreliable on mobile).
|
||||||
|
const shownDuration = duration || (isActive ? engineDuration : 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-3 rounded-lg border bg-transparent px-3 py-2">
|
<div className="flex items-center gap-3 rounded-lg border bg-transparent px-3 py-2">
|
||||||
@@ -151,7 +162,6 @@ export default function AudioPlayer(props: {
|
|||||||
size="icon"
|
size="icon"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
aria-label={playing ? "Pause" : "Play"}
|
aria-label={playing ? "Pause" : "Play"}
|
||||||
disabled={!ready}
|
|
||||||
onClick={() => toggle(props.id)}
|
onClick={() => toggle(props.id)}
|
||||||
>
|
>
|
||||||
{playing ? <Pause /> : <Play />}
|
{playing ? <Pause /> : <Play />}
|
||||||
@@ -171,7 +181,7 @@ export default function AudioPlayer(props: {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span className="w-10 shrink-0 font-mono text-xs text-muted-foreground tabular-nums">
|
<span className="w-10 shrink-0 font-mono text-xs text-muted-foreground tabular-nums">
|
||||||
{formatTime(duration)}
|
{formatTime(shownDuration)}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user