2.0.1 โ€ข Published 5 months ago

react-pro-audio-player v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Custom Audio Player

NPM Version License Downloads

A modern, fully customizable React Audio Player with support for playlists, progress tracking, volume control, loop, playback speed adjustments, and more.

๐ŸŽฎ Demo

Demo GIF


๐Ÿ“œ Table of Contents


๐Ÿš€ Features

โœ… Fully customizable UI with Tailwind CSS support
โœ… Supports playlist playback
โœ… Hybrid & Uncontrolled component usage
โœ… Loop, volume, and playback speed controls
โœ… Supports click-to-play song selection
โœ… Smooth progress tracking and seek
โœ… Lightweight and optimized for performance


๐Ÿ“ฆ Installation

You can install this package via npm or yarn:

npm install react-pro-audio-player

or

yarn add react-pro-audio-player

๐Ÿ“– Usage

1๏ธโƒฃ Hybrid Component

A hybrid component gives you full control over the player's state, such as isPlaying and currentSongIndex, allowing external management of playback.

import React, { useState } from "react";
import CustomAudioPlayer from "react-pro-audio-player";

const songsList = [
  { id: 1, url: "./assets/song1.mp3", title: "Song One" },
  { id: 2, url: "./assets/song2.mp3", title: "Song Two" },
  { id: 3, url: "./assets/song3.mp3", title: "Song Three" },
];

const App = () => {
  const [songs, setSongs] = useState(songsList);
  const [isPlaying, setIsPlaying] = useState(false);
  const [currentSongIndex, setCurrentSongIndex] = useState(null);

  return (
    <>
      <div>
        {songs.map((song, index) => (
          <div key={song.id} onClick={() => setCurrentSongIndex(index)}>
            {song.title}
          </div>
        ))}
      </div>
      {currentSongIndex !== null && (
        <CustomAudioPlayer
          songs={songs}
          isPlaying={isPlaying}
          currentSongIndex={currentSongIndex}
          onPlayPauseChange={setIsPlaying}
          onSongChange={setCurrentSongIndex}
          songUrlKey="url"
          songNameKey="title"
        />
      )}
    </>
  );
};

export default App;

2๏ธโƒฃ Uncontrolled Component

If you want default behavior with minimal setup, use the uncontrolled component. This does not require managing state externally.

import CustomAudioPlayer from "react-pro-audio-player";

const songsList = [
  { id: 1, url: "./assets/song1.mp3", title: "Song One" },
  { id: 2, url: "./assets/song2.mp3", title: "Song Two" },
  { id: 3, url: "./assets/song3.mp3", title: "Song Three" },
];

const App = () => {
  return (
    <CustomAudioPlayer songs={songsList} songUrlKey="url" songNameKey="title" />
  );
};

export default App;

๐ŸŽ›๏ธ Props

PropTypeRequiredDescription
songsArrayโœ… YesList of songs with { id, url, title } objects.
songUrlKeystringโœ… YesThe key name in the song object that stores the song URL
songNameKeystringโœ… YesThe key name in the song object that stores the song name
isPlayingbooleanโŒ NoControls playback state (Hybrid mode only).
currentSongIndexnumberโŒ NoIndex of the currently playing song (Hybrid mode only).
onPlayPauseChangefunctionโŒ NoCallback function to toggle play/pause (Hybrid mode only).
onSongChangefunctionโŒ NoCallback function when song changes (Hybrid mode only).

๐Ÿ“ Note:

  • Props isPlaying, currentSongIndex, onPlayPauseChange, and onSongChange should be used together in Hybrid mode.

๐ŸŽจ Styling & Customization

You can customize the player with CSS classes. The default styles use Tailwind-like classes:

Class NameDescription
.custom-audio-playerMain player container
.player-headerHeader containing song details
.audio-playerInner audio player container
.progress-barCustom progress bar styling
.controls-wrapperWrapper for playback controls
.playback-btnButton for play, pause, next, and previous
.volume-sliderVolume control styling
.playback-speedDropdown for speed selection

๐ŸŽญ Customization

You can enhance the audio player by adding more styles or modifying props. Example of custom styling:

.custom-audio-player {
  background-color: #333;
  color: #fff;
  padding: 10px;
  border-radius: 8px;
}

But need to import the CustomAudioPlayer.css file:

import "react-pro-audio-player/src/CustomAudioPlayer.css";

Before the global css file

import "react-pro-audio-player/src/CustomAudioPlayer.css";
import "./index.css";

๐Ÿค Contributing

We welcome contributions! Hereโ€™s how you can help:

  1. Fork the repository.
  2. Create a new branch (feature-xyz).
  3. Make your changes.
  4. Submit a pull request.

GitHub Repository: CustomAudioPlayer


๐Ÿ“Œ Changelog

v2.0.0 - (Latest Release)

  • ๐ŸŽต Added Hybrid & Uncontrolled component support
  • ๐ŸŽš Improved progress tracking and seek function
  • ๐Ÿ”„ Loop & playback speed controls added
  • ๐ŸŽจ Revamped UI with Tailwind CSS support
  • ๐Ÿ›  Optimized state management for better performance

v1.0.0

  • Initial release with core audio playback features.
  • Play/Pause, Forward/Backward, Volume Control, Loop, and Playback Speed.
  • Responsive UI.

๐Ÿ“ License

This package is open-source and available under the MIT License. Feel free to use and modify it as needed!


๐Ÿš€ Enjoy building with Custom Audio Player! ๐ŸŽง

2.0.1

5 months ago

2.0.0

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago

0.0.1

5 months ago