"use client"; /** * GlobalMiniPlayer * * A sticky bottom bar that appears on any page when the audio reader is * active but the user has navigated away from the reader. Lets them * play / pause / stop without going back to the book, and provides a * direct link back to the reader. * * Visibility logic: * – Hidden when audio state is "idle" (nothing playing) * – Hidden when already ON the reader page (AudioReader handles controls there) * – Shown on every other route inside the app */ import Link from "next/link"; import { usePathname } from "next/navigation"; import { useAudioPlayer, RATES } from "@/lib/audio-player-context"; export function GlobalMiniPlayer() { const { state, currentSeg, segIdx, segTotal, rateIdx, chapterMeta, play, pause, resume, stop, cycleRate, } = useAudioPlayer(); const pathname = usePathname(); // Don't render when idle or no chapter loaded if (state === "idle" || !chapterMeta) return null; // Don't render when the user is already on the reader page if (pathname.startsWith(chapterMeta.readerHref)) return null; const isPlaying = state === "playing"; const progressPct = segTotal > 0 ? Math.round((segIdx / segTotal) * 100) : 0; const togglePlay = () => { if (state === "playing") pause(); else if (state === "paused") resume(); else play(); }; return ( <> {/* EQ bar keyframes (shared with AudioReader) */} {/* Positioned above the mobile bottom nav (pb-20 lg:pb-0) per copilot-instructions. Safe-area-inset-bottom accounts for iPhone home bar. */}
{/* Progress line */}
{/* Controls row */}
{/* Animated EQ / static dot */}
{[ { a: "nxGEqA", d: "0.75s", dl: "0ms", h: 4 }, { a: "nxGEqB", d: "0.9s", dl: "130ms", h: 7 }, { a: "nxGEqC", d: "0.65s", dl: "260ms", h: 5 }, ].map((bar, i) => (
))}
{/* Title + chapter info */}

{chapterMeta.bookTitle}

{isPlaying ? "Now reading · " : "Paused · "} Ch {chapterMeta.number} — {chapterMeta.title} {currentSeg ? ` · ${currentSeg.type === "chapter-title" ? "intro" : currentSeg.type}` : ""}

{/* Speed pill */} {/* Play / Pause */} {/* Stop */} {/* Back-to-reader link */}
); }