This is a light react audio player that is wrapped around a HTML5 audio tag, created for use on American Public Media and Minnesota Public Radio's websites.
npm install apm-react-audio-playerThis is a light react audio player that is wrapped around a HTML5 audio tag, created for use on American Public Media and Minnesota Public Radio's websites.
The library was designed to add a audio player to a body of a story which will not trigger the static audio player.
Installation
- NPM
- YARN
[License] (#License)
As of version 1.0.0, this library has no dependencies for usage.
There are several ways to install APM Player on your site.
``sh`
npm install apm-react-audio-player
or to use yarn:
`sh`
yarn add apm-react-audio-player
The easiest way to include this in modern javascript, assuming you are using something like and Babel, is to use an import statement.
The library uses named exports for all modules.
To import the player module:
`javascript`
import { ReactAudioPlayerInner, useAudioPlayer } from 'apm-react-audio-player';Usage
Prop | Type | Default | Notes
--- | --- | --- | ---
title | String | empty string | The title of the audio trackaudioSrc | String | empty string | The source URL of the audio filedescription | String | empty string | The description of the audio trackaudioPlayerRef | Object | empty object | A ref object for the audio playerprogressBarRef | Object | empty object | A ref object for the progress baronLoadedMetadata | Function | --- | A function to handle the loadedmetadata eventtogglePlaying | Function | --- | A function to toggle the playing stateisPlaying | Boolean | false | Whether the audio is currently playingisMuted | Boolean | false | Whether the audio is currently mutedtoggleMute | Function | --- | A function to toggle the mute statevolumeCtrl | Function | --- | A function to control the volumecurrentTime | Number | null | The current time of the audio trackduration | Number | null | The duration of the audio trackrewindControl | Function | --- | A function to rewind the audio trackforwardControl | Function | --- | A function to fast forward the audio trackchangePlayerCurrentTime | Function | --- | A function to change the current time of the audio trackcalculateTime | Function | --- | A function to calculate the time for the audio trackformatCalculateTime | Function | --- | A function to format the calculated timeplayBtnClass | String | empty string | The CSS class for the play buttoncustomStyles | Object | --- | Custom styles for the audio playercustomHtml | JSX.Element | <>> | Custom HTML to be rendered inside the player
`javascript
import { ReactAudioPlayerInner, useAudioPlayer } from 'apm-react-audio-player';
const Example = () => {
const audioPlayerRef = React.useRef();
const progressBarRef = React.useRef();
const {
onLoadedMetadata,
calculateTime,
volumeControl,
togglePlaying,
toggleMute,
isMuted,
changePlayerCurrentTime,
play,
isPlaying,
isFinishedPlaying,
currentTime,
duration,
formatCalculateTime,
rewindControl,
forwardControl
} = useAudioPlayer(audioPlayerRef, progressBarRef);
return (
audioSrc={'https://play.publicradio.org/web/o/minnesota/podcasts/art_hounds/2024/06/26/arthounds_art-hounds-franconia_20240626_64.mp3'}
description={'description'}
playBtnClass="player-btn player-btn-playpause js-player-play"
audioPlayerRef={audioPlayerRef}
progressBarRef={progressBarRef}
onLoadedMetadata={onLoadedMetadata}
play={play}
isPlaying={isPlaying}
togglePlaying={togglePlaying}
isMuted={isMuted}
currentTime={currentTime}
duration={duration}
isAudioFinished={isFinishedPlaying}
toggleMute={toggleMute}
volumeCtrl={volumeControl}
changePlayerCurrentTime={changePlayerCurrentTime}
rewindControl={rewindControl}
forwardControl={forwardControl}
calculateTime={calculateTime}
formatCalculateTime={formatCalculateTime}
customHtml={<>>}
/>
)
}
`
1. Ensure every merge request and/or change to apm-react-audio-player should always come with an updated version (ex. 1.0.17 to 1.0.18) in the package.json.git pull main
2. Once the changes is on Main branch, locally run:
1. yarn run build
2. or npm run buildyarn publish
3. or npm publish`
MIT © Phanx091