{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "audio-player",
  "title": "Audio Player",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 4 audio player variants: https://avaraui.com/view/audio-player. This item holds 3 of them as looks of one component (hero, bar, native). Skip the question if the user already named one. An audio player with artwork, transport, scrubber and volume, in a hero card, a compact bar, or wrapped around the browser's native controls.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/AudioPlayerBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n  Music,\n  Pause,\n  Play,\n  RotateCcw,\n  RotateCw,\n  Volume2,\n  VolumeX,\n} from \"lucide-react\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\n\n/**\n * How much chrome the player carries.\n *\n * - `hero`   — full artwork card with its own transport (the default).\n * - `bar`    — one compact row: artwork thumb, copy, transport. Fits a sidebar\n *   or the bottom of a page without claiming a hero slot.\n * - `native` — the browser's own `<audio controls>` under the artwork. No\n *   custom transport to keep in sync, and the most accessible by default.\n */\nexport type AudioVariant = \"hero\" | \"bar\" | \"native\";\n\nexport interface AudioPlayerProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onPlay\" | \"onPause\"> {\n  /** Audio file the browser plays natively — mp3, ogg, wav, m4a. */\n  audioUrl?: string;\n  /** MIME type, e.g. `audio/mpeg`. Lets the browser skip a file it cannot play. */\n  audioType?: string;\n  artworkUrl?: string;\n  artworkAlt?: string;\n  badge?: string;\n  title?: string;\n  subtitle?: string;\n  variant?: AudioVariant;\n  enableGlow?: boolean;\n  /** Seconds the skip buttons jump. Set to 0 to hide them. */\n  skipSeconds?: number;\n  loop?: boolean;\n  /**\n   * Start on mount. Browsers refuse unmuted autoplay without a prior\n   * interaction, so treat this as a hint rather than a guarantee.\n   */\n  autoPlay?: boolean;\n  preload?: \"none\" | \"metadata\" | \"auto\";\n  onPlay?: () => void;\n  onPause?: () => void;\n  onEnded?: () => void;\n}\n\n/** `m:ss`, or `—:—` before metadata has arrived. */\nfunction formatTime(seconds: number): string {\n  if (!Number.isFinite(seconds) || seconds < 0) return \"--:--\";\n  const total = Math.floor(seconds);\n  const mins = Math.floor(total / 60);\n  const secs = total % 60;\n  return `${mins}:${String(secs).padStart(2, \"0\")}`;\n}\n\nconst ICON_BUTTON =\n  \"flex items-center justify-center rounded-full text-white/70 transition-colors duration-200 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/60 cursor-pointer disabled:cursor-not-allowed disabled:opacity-40\";\n\nexport const AudioPlayer = React.forwardRef<\n  HTMLDivElement,\n  AudioPlayerProps\n>(\n  (\n    {\n      audioUrl = \"https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3\",\n      audioType = \"audio/mpeg\",\n      artworkUrl = \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_1200,c_limit/v1790145142/photo-1511671782779-c97d3d27a1d4-1790145143493.jpg\",\n      artworkAlt = \"Album artwork\",\n      badge = \"Now Playing\",\n      title = \"It All Began With a Burst\",\n      subtitle = \"Kishi Bashi — 151a\",\n      variant = \"hero\",\n      enableGlow = true,\n      skipSeconds = 10,\n      loop = false,\n      autoPlay = false,\n      preload = \"metadata\",\n      onPlay,\n      onPause,\n      onEnded,\n      className,\n      ...props\n    },\n    ref,\n  ) => {\n    const audioRef = useRef<HTMLAudioElement>(null);\n    const [isPlaying, setIsPlaying] = useState(false);\n    const [currentTime, setCurrentTime] = useState(0);\n    const [duration, setDuration] = useState(0);\n    const [volume, setVolume] = useState(1);\n    const [isMuted, setIsMuted] = useState(false);\n\n    // The <audio> element is the source of truth for playback state, not React.\n    // Anything can change it — the native controls, a media key, the OS — so the\n    // UI mirrors its events rather than assuming its own clicks are the only\n    // way it moves.\n    useEffect(() => {\n      const audio = audioRef.current;\n      if (!audio) return;\n\n      const onLoaded = () => setDuration(audio.duration);\n      const onTime = () => setCurrentTime(audio.currentTime);\n      const onPlaying = () => setIsPlaying(true);\n      const onPaused = () => setIsPlaying(false);\n      const onEnd = () => {\n        setIsPlaying(false);\n        onEnded?.();\n      };\n      const onVolume = () => {\n        setVolume(audio.volume);\n        setIsMuted(audio.muted);\n      };\n\n      audio.addEventListener(\"loadedmetadata\", onLoaded);\n      audio.addEventListener(\"durationchange\", onLoaded);\n      audio.addEventListener(\"timeupdate\", onTime);\n      audio.addEventListener(\"play\", onPlaying);\n      audio.addEventListener(\"pause\", onPaused);\n      audio.addEventListener(\"ended\", onEnd);\n      audio.addEventListener(\"volumechange\", onVolume);\n      return () => {\n        audio.removeEventListener(\"loadedmetadata\", onLoaded);\n        audio.removeEventListener(\"durationchange\", onLoaded);\n        audio.removeEventListener(\"timeupdate\", onTime);\n        audio.removeEventListener(\"play\", onPlaying);\n        audio.removeEventListener(\"pause\", onPaused);\n        audio.removeEventListener(\"ended\", onEnd);\n        audio.removeEventListener(\"volumechange\", onVolume);\n      };\n    }, [onEnded]);\n\n    const toggle = useCallback(() => {\n      const audio = audioRef.current;\n      if (!audio) return;\n      if (audio.paused) {\n        // A blocked autoplay rejects rather than throwing, and an unhandled\n        // rejection here would surface as a console error on every locked tab.\n        void audio.play().then(() => onPlay?.()).catch(() => setIsPlaying(false));\n      } else {\n        audio.pause();\n        onPause?.();\n      }\n    }, [onPlay, onPause]);\n\n    const skip = useCallback((delta: number) => {\n      const audio = audioRef.current;\n      if (!audio) return;\n      const limit = Number.isFinite(audio.duration) ? audio.duration : Infinity;\n      audio.currentTime = Math.min(Math.max(audio.currentTime + delta, 0), limit);\n    }, []);\n\n    const seek = (value: number) => {\n      const audio = audioRef.current;\n      if (!audio) return;\n      audio.currentTime = value;\n      setCurrentTime(value);\n    };\n\n    const changeVolume = (value: number) => {\n      const audio = audioRef.current;\n      if (!audio) return;\n      audio.volume = value;\n      audio.muted = value === 0;\n    };\n\n    const toggleMute = () => {\n      const audio = audioRef.current;\n      if (!audio) return;\n      audio.muted = !audio.muted;\n    };\n\n    const progress = duration > 0 ? (currentTime / duration) * 100 : 0;\n    const accent = \"var(--theme-color, var(--primary))\";\n\n    const audioElement = (\n      <audio\n        ref={audioRef}\n        // Remount on a changed src: <audio> ignores the attribute once it has\n        // already loaded metadata for the previous one.\n        key={audioUrl}\n        loop={loop}\n        autoPlay={autoPlay}\n        preload={preload}\n        controls={variant === \"native\"}\n        className={variant === \"native\" ? \"w-full\" : \"hidden\"}\n      >\n        <source src={audioUrl} type={audioType} />\n        Your browser does not support the audio element.\n      </audio>\n    );\n\n    const copy = (\n      <div className=\"min-w-0\">\n        {badge && (\n          <span className=\"mb-1.5 inline-flex items-center gap-1.5 rounded-full border border-white/20 bg-white/10 px-2.5 py-1 text-[10px] font-semibold tracking-wider text-white uppercase backdrop-blur-md\">\n            <Music className=\"h-3 w-3 shrink-0 text-amber-400\" />\n            {badge}\n          </span>\n        )}\n        {title && (\n          <h3 className=\"truncate text-base font-extrabold tracking-tight text-white sm:text-xl md:text-2xl\">\n            {title}\n          </h3>\n        )}\n        {subtitle && (\n          <p className=\"truncate text-[11px] text-zinc-400 sm:text-sm\">\n            {subtitle}\n          </p>\n        )}\n      </div>\n    );\n\n    const scrubber = (\n      <div className=\"flex items-center gap-2.5\">\n        <span className=\"w-10 shrink-0 text-right font-mono text-[10px] text-zinc-400 tabular-nums sm:text-xs\">\n          {formatTime(currentTime)}\n        </span>\n        <div className=\"relative flex-1\">\n          {/* The filled track is a plain div behind a transparent range input —\n              `accent-color` alone cannot be themed per-instance, and a styled\n              input loses the native keyboard behaviour this keeps. */}\n          <div className=\"h-1.5 w-full overflow-hidden rounded-full bg-white/15\">\n            <div\n              className=\"h-full rounded-full transition-[width] duration-100 ease-linear\"\n              style={{ width: `${progress}%`, background: accent }}\n            />\n          </div>\n          <input\n            type=\"range\"\n            min={0}\n            max={duration || 0}\n            step={0.1}\n            value={currentTime}\n            onChange={(e) => seek(Number(e.target.value))}\n            disabled={!duration}\n            aria-label=\"Seek\"\n            className=\"absolute inset-0 h-full w-full cursor-pointer appearance-none bg-transparent opacity-0 disabled:cursor-not-allowed\"\n          />\n        </div>\n        <span className=\"w-10 shrink-0 font-mono text-[10px] text-zinc-400 tabular-nums sm:text-xs\">\n          {formatTime(duration)}\n        </span>\n      </div>\n    );\n\n    const transport = (\n      <div className=\"flex items-center gap-2 sm:gap-3\">\n        {skipSeconds > 0 && (\n          <button\n            type=\"button\"\n            onClick={() => skip(-skipSeconds)}\n            className={cn(ICON_BUTTON, \"h-9 w-9\")}\n            aria-label={`Rewind ${skipSeconds} seconds`}\n          >\n            <RotateCcw className=\"h-4 w-4\" />\n          </button>\n        )}\n\n        <button\n          type=\"button\"\n          onClick={toggle}\n          style={{ background: accent }}\n          className=\"flex h-12 w-12 shrink-0 cursor-pointer items-center justify-center rounded-full text-primary-foreground shadow-lg transition-transform duration-200 hover:scale-105 focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-zinc-900 focus-visible:outline-none active:scale-95 sm:h-14 sm:w-14\"\n          aria-label={isPlaying ? \"Pause\" : \"Play\"}\n        >\n          {isPlaying ? (\n            <Pause className=\"h-5 w-5 fill-current sm:h-6 sm:w-6\" />\n          ) : (\n            <Play className=\"ml-0.5 h-5 w-5 fill-current sm:h-6 sm:w-6\" />\n          )}\n        </button>\n\n        {skipSeconds > 0 && (\n          <button\n            type=\"button\"\n            onClick={() => skip(skipSeconds)}\n            className={cn(ICON_BUTTON, \"h-9 w-9\")}\n            aria-label={`Forward ${skipSeconds} seconds`}\n          >\n            <RotateCw className=\"h-4 w-4\" />\n          </button>\n        )}\n      </div>\n    );\n\n    const volumeControl = (\n      <div className=\"flex items-center gap-2\">\n        <button\n          type=\"button\"\n          onClick={toggleMute}\n          className={cn(ICON_BUTTON, \"h-8 w-8\")}\n          aria-label={isMuted ? \"Unmute\" : \"Mute\"}\n        >\n          {isMuted || volume === 0 ? (\n            <VolumeX className=\"h-4 w-4\" />\n          ) : (\n            <Volume2 className=\"h-4 w-4\" />\n          )}\n        </button>\n        <input\n          type=\"range\"\n          min={0}\n          max={1}\n          step={0.01}\n          value={isMuted ? 0 : volume}\n          onChange={(e) => changeVolume(Number(e.target.value))}\n          aria-label=\"Volume\"\n          className=\"h-1 w-16 cursor-pointer appearance-none rounded-full bg-white/20 sm:w-20 [&::-webkit-slider-thumb]:h-3 [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-white\"\n        />\n      </div>\n    );\n\n    const glow = enableGlow ? (\n      <div className=\"pointer-events-none absolute -inset-4 z-0 rounded-3xl bg-gradient-to-tr from-indigo-500/20 via-purple-500/20 to-pink-500/10 opacity-80 blur-3xl transition-opacity duration-500 dark:opacity-50\" />\n    ) : null;\n\n    /* ── bar: one compact row ─────────────────────────────────────────────── */\n    if (variant === \"bar\") {\n      return (\n        <div\n          ref={ref}\n          className={cn(\"relative w-full\", className)}\n          {...props}\n        >\n          {glow}\n          {audioElement}\n          <div className=\"relative z-10 flex w-full items-center gap-3 rounded-2xl border border-border/80 bg-zinc-900 p-3 shadow-2xl sm:gap-5 sm:p-4\">\n            <img\n              src={artworkUrl}\n              alt={artworkAlt}\n              loading=\"lazy\"\n              className=\"h-14 w-14 shrink-0 rounded-xl object-cover sm:h-16 sm:w-16\"\n            />\n            <div className=\"flex min-w-0 flex-1 flex-col gap-2\">\n              {copy}\n              {scrubber}\n            </div>\n            <div className=\"flex shrink-0 items-center gap-3\">\n              {transport}\n              <div className=\"hidden sm:block\">{volumeControl}</div>\n            </div>\n          </div>\n        </div>\n      );\n    }\n\n    /* ── hero + native: artwork card ──────────────────────────────────────── */\n    return (\n      <div ref={ref} className={cn(\"relative w-full\", className)} {...props}>\n        {glow}\n        <div className=\"relative z-10 flex w-full flex-col overflow-hidden rounded-2xl border border-border/80 bg-zinc-900 shadow-2xl md:flex-row md:rounded-3xl\">\n          <div className=\"relative aspect-square w-full shrink-0 overflow-hidden md:aspect-auto md:w-64 lg:w-80\">\n            <img\n              src={artworkUrl}\n              alt={artworkAlt}\n              loading=\"lazy\"\n              className=\"h-full w-full object-cover\"\n            />\n            <div className=\"absolute inset-0 bg-gradient-to-t from-zinc-900/80 to-transparent md:bg-gradient-to-r\" />\n          </div>\n\n          <div className=\"flex flex-1 flex-col justify-center gap-4 p-5 sm:gap-5 sm:p-8\">\n            {copy}\n\n            {variant === \"native\" ? (\n              audioElement\n            ) : (\n              <>\n                {scrubber}\n                <div className=\"flex items-center justify-between gap-4\">\n                  {transport}\n                  {volumeControl}\n                </div>\n              </>\n            )}\n          </div>\n        </div>\n        {variant !== \"native\" && audioElement}\n      </div>\n    );\n  },\n);\n\nAudioPlayer.displayName = \"AudioPlayer\";\n",
      "type": "registry:component",
      "target": "components/custom/blocks/AudioPlayerBlock.tsx"
    }
  ],
  "docs": "Named export: AudioPlayer. `audioUrl` and `artworkUrl` drive it; `variant` is hero | bar | native. Built on a plain <audio> element with no player library, so it adds no npm weight beyond the icons. Playback state mirrors the element's own events, which keeps it correct when a media key or the native controls change it. `skipSeconds` sizes the jump buttons (0 hides them) and the accent follows `--theme-color`.",
  "categories": [
    "marketing",
    "media"
  ],
  "type": "registry:component"
}
