Music Player
ui-components/music-playerFreeBlock
A music player component featuring essential playback controls and a progress slider.
Install it
npx shadcn@latest add https://ui.raulcarini.dev/r/music-player.jsonSource
1"use client";23import { cn } from "@/lib/utils";4import { Button } from "@/components/ui/button";5import { Slider } from "@/components/ui/slider";6import {7 PauseIcon,8 RepeatIcon,9 ShuffleIcon,10 SkipBackIcon,11 SkipForwardIcon,12 MusicIcon,13 PlayIcon,14 Repeat1Icon,15} from "lucide-react";16import { useMusicPlayer, Song } from "@/hooks/use-music-player";1718export default function MusicPlayer({ song }: { song: Song }) {19 const {20 isPlaying,21 duration,22 progressPercentage,23 formattedCurrentTime,24 formattedDuration,25 isShuffling,26 repeatMode,27 togglePlayPause,28 handleSliderChange,29 toggleShuffle,30 toggleRepeat,31 } = useMusicPlayer({ song });3233 return (34 <div className="md:max-w-md w-full flex flex-col gap-4 bg-popover border rounded-lg p-4">35 <div className="flex items-start md:items-center flex-col md:flex-row gap-4 min-w-0">36 {song.album.image ? (37 <img38 src={song.album.image}39 alt={`${song.name} by ${song.artists.join(", ")}`}40 className="size-full md:size-16 rounded-md object-cover"41 aria-hidden="true"42 />43 ) : (44 <div45 className="size-full md:size-16 rounded-md bg-muted flex items-center justify-center"46 aria-hidden="true"47 >48 <MusicIcon className="size-8 text-muted-foreground" />49 </div>50 )}51 <div className="w-full">52 <p className="text-lg font-semibold truncate">{song.name}</p>53 <p className="text-sm text-muted-foreground truncate">54 {song.artists.join(", ")}55 </p>56 <p className="text-sm text-muted-foreground truncate">57 {song.album.name}58 </p>59 </div>60 </div>61 <div className="relative">62 <Slider63 value={[progressPercentage]}64 max={100}65 step={1}66 aria-label="Music progress slider"67 onValueChange={handleSliderChange}68 disabled={duration === 0}69 />70 <div className="w-full flex justify-between mt-1.5 text-xs text-muted-foreground">71 <span>{formattedCurrentTime}</span>72 <span>{formattedDuration}</span>73 </div>74 </div>75 <div className="flex items-center justify-center -mt-2 -mb-1">76 <Button77 variant="ghost"78 size="icon"79 className={cn(80 "size-7 mr-1.5",81 isShuffling ? "text-primary" : "text-muted-foreground",82// … truncated
What it pulls in
Other registry items
Files it writes
More from UI Components
All 25 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| GitHub Contributionsgithub-contributions | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Advancedgithub-contributions-advanced | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Advanced Fetchergithub-contributions-advanced-fetcher | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Fetchergithub-contributions-fetcher | UI Components | Blocks | Free | no deps | |
| GitHub Forksgithub-forks | UI Components | Blocks | Free | 1 dep | |
| GitHub Issuesgithub-issues | UI Components | Blocks | Free | 1 dep | |
| GitHub Pull Requestsgithub-pr | UI Components | Blocks | Free | 1 dep | |
| GitHub Starsgithub-stars | UI Components | Blocks | Free | 1 dep |
