{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "media-player",
  "type": "registry:component",
  "title": "Media player",
  "description": "Inline audio card with play/pause, seekable waveform and regenerate/download actions. Based on the MCP Apps for Claude kit.",
  "registryDependencies": [
    "https://mcpblocks.dev/r/host-tokens.json",
    "https://mcpblocks.dev/r/icons.json"
  ],
  "files": [
    {
      "path": "registry/mcpblocks/components/media-player.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { DownloadIcon, PauseIcon, PlayIcon, ReloadIcon } from \"@/registry/mcpblocks/ui/icons\"\n\nexport type MediaPlayerProps = {\n  title: string\n  subtitle?: string\n  /** Audio source. Without it the player renders as a static preview. */\n  src?: string\n  /** Duration in seconds, shown before metadata loads. */\n  duration?: number\n  /**\n   * Waveform peaks between 0 and 1. If omitted, a stable placeholder\n   * waveform is generated from the title.\n   */\n  peaks?: number[]\n  onRegenerate?: () => void\n  onDownload?: () => void\n  className?: string\n}\n\nfunction formatTime(s: number) {\n  if (!Number.isFinite(s)) return \"0:00\"\n  const m = Math.floor(s / 60)\n  const sec = Math.floor(s % 60)\n  return `${m}:${sec.toString().padStart(2, \"0\")}`\n}\n\nfunction placeholderPeaks(seed: string, n = 64) {\n  let h = 2166136261\n  for (let i = 0; i < seed.length; i++) h = Math.imul(h ^ seed.charCodeAt(i), 16777619)\n  const out: number[] = []\n  for (let i = 0; i < n; i++) {\n    h = Math.imul(h ^ (h >>> 15), 2246822507)\n    const r = ((h >>> 0) % 1000) / 1000\n    const envelope = 0.35 + 0.65 * Math.sin((i / n) * Math.PI)\n    out.push(Math.max(0.12, Math.min(1, r * envelope + 0.1)))\n  }\n  return out\n}\n\n/**\n * Inline audio card with play/pause, waveform scrubber and actions.\n * Matches the \"Media card\" pattern in the MCP Apps for Claude kit.\n */\nexport function MediaPlayer({\n  title,\n  subtitle,\n  src,\n  duration: initialDuration = 0,\n  peaks,\n  onRegenerate,\n  onDownload,\n  className,\n}: MediaPlayerProps) {\n  const audioRef = React.useRef<HTMLAudioElement>(null)\n  const [playing, setPlaying] = React.useState(false)\n  const [time, setTime] = React.useState(0)\n  const [duration, setDuration] = React.useState(initialDuration)\n  const bars = React.useMemo(() => peaks ?? placeholderPeaks(title), [peaks, title])\n  const progress = duration > 0 ? time / duration : 0\n\n  function toggle() {\n    const a = audioRef.current\n    if (!a) return\n    if (a.paused) void a.play()\n    else a.pause()\n  }\n\n  function seek(e: React.MouseEvent<HTMLDivElement>) {\n    const a = audioRef.current\n    if (!a || !duration) return\n    const rect = e.currentTarget.getBoundingClientRect()\n    a.currentTime = ((e.clientX - rect.left) / rect.width) * duration\n  }\n\n  return (\n    <div\n      data-slot=\"media-player\"\n      className={cn(\"flex w-full flex-col gap-6 p-6 text-host-fg font-[family-name:var(--font-sans)]\", className)}\n    >\n      <div className=\"flex items-center justify-between gap-3\">\n        <div className=\"flex min-w-0 flex-col text-base leading-[1.4]\">\n          <span className=\"truncate font-semibold\">{title}</span>\n          {subtitle ? <span className=\"truncate text-host-fg-tertiary\">{subtitle}</span> : null}\n        </div>\n        <div className=\"flex shrink-0 items-center gap-3\">\n          {onRegenerate ? (\n            <button\n              type=\"button\"\n              onClick={onRegenerate}\n              aria-label=\"Regenerate\"\n              className=\"inline-flex size-11 items-center justify-center rounded-host-md border-[length:var(--border-width-regular,0.5px)] border-host-border text-host-fg hover:bg-host-bg-secondary\"\n            >\n              <ReloadIcon className=\"size-5\" />\n            </button>\n          ) : null}\n          {onDownload ? (\n            <button\n              type=\"button\"\n              onClick={onDownload}\n              aria-label=\"Download\"\n              className=\"inline-flex size-11 items-center justify-center rounded-host-md bg-host-bg-inverse text-host-fg-inverse hover:opacity-90\"\n            >\n              <DownloadIcon className=\"size-5\" />\n            </button>\n          ) : null}\n        </div>\n      </div>\n\n      <div className=\"flex items-center gap-4\">\n        <button\n          type=\"button\"\n          onClick={toggle}\n          disabled={!src}\n          aria-label={playing ? \"Pause\" : \"Play\"}\n          className=\"inline-flex size-11 shrink-0 items-center justify-center rounded-full bg-host-bg-inverse text-host-fg-inverse disabled:cursor-default\"\n        >\n          {playing ? <PauseIcon className=\"size-5\" /> : <PlayIcon className=\"size-5 translate-x-px\" />}\n        </button>\n\n        <div\n          role=\"slider\"\n          tabIndex={0}\n          aria-label=\"Seek\"\n          aria-valuemin={0}\n          aria-valuemax={Math.round(duration)}\n          aria-valuenow={Math.round(time)}\n          onClick={seek}\n          onKeyDown={(e) => {\n            const a = audioRef.current\n            if (!a) return\n            if (e.key === \"ArrowRight\") a.currentTime = Math.min(duration, a.currentTime + 5)\n            if (e.key === \"ArrowLeft\") a.currentTime = Math.max(0, a.currentTime - 5)\n          }}\n          className=\"flex h-11 min-w-0 flex-1 cursor-pointer items-center gap-[3px] [mask-image:linear-gradient(to_right,transparent,black_12%,black_88%,transparent)]\"\n        >\n          {bars.map((p, i) => (\n            <span\n              key={i}\n              aria-hidden=\"true\"\n              className={cn(\n                \"w-[3px] min-w-[2px] flex-1 rounded-full transition-colors\",\n                i / bars.length <= progress ? \"bg-host-fg\" : \"bg-host-fg-tertiary/60\"\n              )}\n              style={{ height: `${Math.round(p * 100)}%` }}\n            />\n          ))}\n        </div>\n\n        <span className=\"min-w-9 shrink-0 text-center text-sm leading-[1.4] text-host-fg-tertiary tabular-nums\">\n          {formatTime(playing || time > 0 ? time : duration)}\n        </span>\n      </div>\n\n      {src ? (\n        <audio\n          ref={audioRef}\n          src={src}\n          preload=\"metadata\"\n          onPlay={() => setPlaying(true)}\n          onPause={() => setPlaying(false)}\n          onEnded={() => setPlaying(false)}\n          onTimeUpdate={(e) => setTime(e.currentTarget.currentTime)}\n          onLoadedMetadata={(e) => setDuration(e.currentTarget.duration)}\n        />\n      ) : null}\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ]
}