audio-player-ts
v1.2.0
Published
Certainly! Here's an expanded README with all the functionalities of your audio player package along with usage examples:
Downloads
1
Readme
Certainly! Here's an expanded README with all the functionalities of your audio player package along with usage examples:
Audio Player
Description
A customizable audio player package built with TypeScript, providing features like play, pause, resume, next track, seek, volume control, and more.
Installation
Install the package in your project using npm or yarn:
npm install audio-player
# or
yarn add audio-player
Usage
Import the
AudioPlayer
class in your React component:import React, { useState } from 'react'; import AudioPlayer from 'audio-player'; const App = () => { const [player] = useState(() => { const playlist = ['path/to/track1.mp3', 'path/to/track2.mp3']; // Example playlist return new AudioPlayer(playlist); }); const [position, setPosition] = useState(0); const handleSeek = (value) => { setPosition(value); player.seek(value); }; return ( <div> <button onClick={() => player.play()}>Play</button> <button onClick={() => player.pause()}>Pause</button> <button onClick={() => player.resume()}>Resume</button> <button onClick={() => player.next()}>Next</button> <button onClick={() => player.increaseVolume()}>Increase Volume</button> <button onClick={() => player.decreaseVolume()}>Decrease Volume</button> <input type="range" min="0" max="100" value={position} onChange={(e) => handleSeek(parseInt(e.target.value))} /> {/* Add more buttons or controls as needed */} </div> ); } export default App;
Customize the player with your audio files and controls:
- Replace
'path/to/track1.mp3'
,'path/to/track2.mp3'
, etc., with the paths to your audio files. - Adjust the range input according to your design and UI requirements.
- Add more buttons or controls by calling other methods of the
AudioPlayer
class, such asresume()
,next()
,increaseVolume()
,decreaseVolume()
, etc.
- Replace
Run your React app and test the audio player functionality:
npm start
Functionality
play()
: Start playing the current audio track.player.play();
pause()
: Pause the currently playing audio track.player.pause();
resume()
: Resume playback of the paused audio track.player.resume();
next()
: Play the next track in the playlist.player.next();
seek(position: number)
: Seek to a specific position in the audio track (0-100).player.seek(50); // Seek to halfway through the track
increaseVolume()
: Increase the volume of the audio player.player.increaseVolume();
decreaseVolume()
: Decrease the volume of the audio player.player.decreaseVolume();
getCurrentTrackIndex()
: Get the index of the currently playing track in the playlist.const currentIndex = player.getCurrentTrackIndex();
getPlaybackPosition()
: Get the current playback position of the audio track.const position = player.getPlaybackPosition();
getVolume()
: Get the current volume level of the audio player.const volume = player.getVolume();
setVolume(volume: number)
: Set the volume level of the audio player (0-1).player.setVolume(0.8); // Set volume to 80%
Documentation
For detailed API documentation and usage examples, refer to the Audio Player GitHub repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
This README includes all the functionalities of your audio player package along with usage examples for each functionality. Users can refer to this README to understand how to use the package and its various features in their React projects. Adjust the examples and descriptions according to the actual implementation and API of your `AudioPlayer` class.