The Audio Player App is a React-based web application that allows users to upload and play audio files effortlessly. It provides a seamless way to manage a playlist, offering features such as uploading new audio files, deleting specific files, and playing audio with the standard HTML audio player.
This repository follows a clean and organized structure to enhance readability and maintainability.
.
├── public
│ └── index.html
├── src
│ ├── components
│ │ ├── AudioPlayer
│ │ │ └── AudioPlayer.jsx
│ │ ├── FileUploader
│ │ │ └── FileUploader.jsx
│ │ ├── Playlist
│ │ │ └── Playlist.jsx
│ ├── App.jsx
│ ├── index.js
├── .gitignore
├── package.json
├── README.md
└── other configuration files
-
File Upload
- Users can upload audio files (e.g., mp3).
- Utilizes the FileUploader component to handle file uploads.
-
Audio Storage
- Stores audio files using built-in Browser APIs.
- Uses localStorage to store the playlist and individual audio files.
-
Playlist and Now Playing View
- Displays a dynamic playlist in the Playlist component.
- Shows a sleek now playing view in the AudioPlayer component.
-
Playback Control
- Users can easily play any file from the playlist.
- Playback seamlessly continues to the next file upon completion.
- Utilizes standard HTML audio player controls for intuitive playback.
-
Persistent State
- Saves the last playing audio file and its position in localStorage.
- Upon page reload, the app loads the last playing audio file and continues playback from the last position.
-
Standard HTML Audio Player
- Incorporates the standard built-in HTML audio player.
- Avoids third-party players for simplicity, ensuring a lightweight and native experience.
-
Responsive Design
- Utilizes Tailwind CSS for a responsive and mobile-friendly design.
- Ensures a consistent and enjoyable user experience across various devices.
- React
- Tailwind CSS
- HTML
- JavaScript
- Browser APIs
- localStorage
-
Clone the repository:
git clone https://github.com/Rajkumar-Khatua/audio-player-app.git
-
Navigate to the project directory:
cd audio-player-app
-
Install the dependencies:
npm install
-
Start the development server:
npm start
-
Open the browser and visit
http://localhost:5173/
to view the app.
The Audio Player App is built using React and standard HTML audio player controls. It uses the FileUploader component to handle file uploads and the Playlist component to display the playlist. The AudioPlayer component provides a sleek now playing view and seamless playback control.
The app stores audio files using built-in Browser APIs and utilizes localStorage to store the playlist and individual audio files. It also saves the last playing audio file and its position in localStorage, ensuring a persistent state across page reloads.
The app is designed to be responsive and mobile-friendly, ensuring a consistent and enjoyable user experience across various devices.
In this project, the Blob (Binary Large Object) is employed as a data structure to represent audio files. Blobs are binary data containers, allowing for the storage of audio file content in a format compatible with the HTML audio element.
The base64StringToBlob
helper function is used to convert base64-encoded strings retrieved from localStorage
back into Blob objects. This process ensures that the audio file data can be reconstructed accurately for playback.
const base64StringToBlob = (base64String) => {
// Implementation details of converting base64 to Blob
// ...
return new Blob(byteArrays, { type: contentType });
};
The URL.createObjectURL
method is used to create a URL for the Blob object, allowing the audio file to be played using the HTML audio player. This method generates a unique URL for the Blob, which can be used as the audio source.
const audioBlob = base64StringToBlob(base64String);
const audioUrl = URL.createObjectURL(audioBlob);
To add audio files to the playlist, follow these steps:
- Click on the "File Uploader" section.
- Use the "Upload File" button to select and upload MP3 files.
- Supported format:
.mp3
- The uploaded files will be displayed in the "Playlist" section.
- Click on a file in the playlist to play it.
- The currently playing audio is highlighted in the playlist.
- Utilize the standard HTML audio player controls to play, pause, adjust volume, and seek through the audio.
- The now playing view displays whether the audio is playing or paused.
- The project automatically proceeds to the next audio file upon completion.
- The playlist and last played audio information persist even if the page is reloaded.
- Remove a specific audio file from the playlist by clicking the "Delete" button next to it.
- Delete all files in the playlist using the "Delete All" button.
- The user interface is styled using Tailwind CSS, providing a clean and responsive design.
- The project ensures continuous playback, automatically moving to the next audio file upon completion.
- The project remembers the last played position of an audio file, allowing users to resume playback from the same position after a page reload.
- The project uses the standard built-in HTML audio player, ensuring compatibility across various web browsers without relying on third-party players.