Ravi Katiyar

Music Player Card

Cards 79

About

Music Player Card A visually polished and interactive music player card component. It features a glassmorphism effect, animated progress bar, and theme-adaptive styling, making it suitable for modern web applications.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Music Player Card to your project and fits it to your theme.

Code

How Music Player Card is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import * as React from "react";
import { MusicPlayerCard } from "@/components/ui/music-player-card";

const DURATION_IN_SECONDS = 185; // e.g., 3 minutes and 5 seconds

export default function MusicPlayerDemo() {
  const [isPlaying, setIsPlaying] = React.useState<boolean>(false);
  const [isLiked, setIsLiked] = React.useState<boolean>(false);
  const [currentProgress, setCurrentProgress] = React.useState<number>(52); // Start at 52 seconds

  // Effect to simulate song progress with advanced animation
  React.useEffect(() => {
    let interval: NodeJS.Timeout;
    if (isPlaying) {
      interval = setInterval(() => {
        setCurrentProgress((prev) => {
          if (prev >= DURATION_IN_SECONDS) {
            setIsPlaying(false); // Stop playing when song ends
            return 0; // Reset progress
          }
          return prev + 1;
        });
      }, 1000);
    }
    // Cleanup on component unmount or when isPlaying changes
    return () => clearInterval(interval);
  }, [isPlaying]);

  const handlePlayPause = () => {
    setIsPlaying((prev) => !prev);
  };

  const handleLike = () => {
    setIsLiked((prev) => !prev);
  };
  
  const handleNext = () => {
    console.log("Next button clicked");
    // Logic to skip to the next track
    setCurrentProgress(0); // Reset progress for demo
  };

  const handlePrev = () => {
    console.log("Previous button clicked");
    // Logic to go to the previous track
    setCurrentProgress(0); // Reset progress for demo
  };
  
  const handleShare = () => {
    console.log("Share button clicked");
    // Logic to open share dialog
  };

  return (
    <div className="flex h-screen w-full items-center justify-center bg-background p-4">
      <MusicPlayerCard
        artistName="Terence Howard"
        artistHandle="@terenceh"
        avatarSrc="https://cdn.21st.dev/assets/mirror/21/21d021e881d1d1c7387c092e3c0823f851433814e907717eb3373166c9fd8f2b.jpg"
        albumArtSrc="https://cdn.21st.dev/assets/mirror/81/81847341f11bf6f57664c06e6d5827e684b4d96f51ba0b087544be7f96f1ef01.jpg"
        songDuration={DURATION_IN_SECONDS}
        currentProgress={currentProgress}
        isPlaying={isPlaying}
        isLiked={isLiked}
        onPlayPauseClick={handlePlayPause}
        onLikeClick={handleLike}
        onNextClick={handleNext}
        onPrevClick={handlePrev}
        onShareClick={handleShare}
      />
    </div>
  );
}

Dependencies

More by Ravi Katiyar

View all
  • Animated Shader Hero

    Animated Shader Hero

    3.7K
  • Hero

    Hero

    3.1K
  • Circular Gallery

    Circular Gallery

    2.7K
  • Minimalist Hero

    Minimalist Hero

    2.5K
  • Floating Icons Hero Section

    Floating Icons Hero Section

    1.9K
  • Glass Calendar

    Glass Calendar

    1.8K
  • Feature Carousel

    Feature Carousel

    1.7K
  • AI Image Generator Hero

    AI Image Generator Hero

    1.4K

More in Cards

View all
  • Stats cards with links

    Stats cards with links

    33
  • Course Design Cards

    Course Design Cards

    1.1K
  • Card

    Card

    70
  • Statistics Card 2

    Statistics Card 2

    264
  • Statistics Card 10

    Statistics Card 10

    263
  • Card

    Card

    17
  • Card Studio

    Card Studio

    9
  • The Item one

    The Item one

    3