Gathering detailed insights and metrics for react-h5-audio-player
Gathering detailed insights and metrics for react-h5-audio-player
Gathering detailed insights and metrics for react-h5-audio-player
Gathering detailed insights and metrics for react-h5-audio-player
@demu/react-h5-audio-player
A customizable React audio player. Written in TypeScript. Mobile compatible. Keyboard friendly
@fortissimo-deps/react-h5-audio-player
A customizable React audio player. Written in TypeScript. Mobile compatible. Keyboard friendly
react-moskaj-audio-player
react h5 audio with customized icons_A React audio player with UI. Mobile compatible.
@hailin_yin/react-h5-audio-player
A customizable React audio player. Written in TypeScript. Mobile compatible. Keyboard friendly
npm install react-h5-audio-player
Typescript
Module System
Node Version
NPM Version
89.5
Supply Chain
94.5
Quality
84
Maintenance
100
Vulnerability
100
License
TypeScript (54.5%)
JavaScript (27.42%)
MDX (13.69%)
SCSS (4.34%)
Shell (0.06%)
Total Downloads
4,234,066
Last Day
3,836
Last Week
29,281
Last Month
149,570
Last Year
1,450,915
633 Stars
197 Commits
97 Forks
10 Watching
4 Branches
11 Contributors
Latest Version
3.9.3
Package Id
react-h5-audio-player@3.9.3
Unpacked Size
286.40 kB
Size
53.98 kB
File Count
54
NPM Version
10.1.0
Node Version
20.9.0
Publised On
01 Jul 2024
Cumulative downloads
Total Downloads
Last day
-40%
3,836
Compared to previous day
Last week
-22.2%
29,281
Compared to previous week
Last month
10.3%
149,570
Compared to previous month
Last year
33%
1,450,915
Compared to previous year
2
39
Live Demo: Storybook
Try it on CodePen: Basic, Playlist
Supported browsers: Chrome, Firefox, Safari, Edge
$ npm i react-h5-audio-player
Or
$ yarn add react-h5-audio-player
1import AudioPlayer from 'react-h5-audio-player'; 2import 'react-h5-audio-player/lib/styles.css'; 3// import 'react-h5-audio-player/lib/styles.less' Use LESS 4// import 'react-h5-audio-player/src/styles.scss' Use SASS 5 6const Player = () => ( 7 <AudioPlayer 8 autoPlay 9 src="http://example.com/audio.mp3" 10 onPlay={e => console.log("onPlay")} 11 // other props here 12 /> 13);
They can be turned off by setting hasDefaultKeyBindings
prop to false
Key binding | Action |
---|---|
Space | Play/Pause |
← | Rewind |
→ | Forward |
↑ | Volume up |
↓ | Volume down |
L | Toggle loop |
M | Toggle mute |
Props | Type | Default | Note |
---|---|---|---|
src | string | '' | |
preload | 'auto' | 'metadata' | 'none' | 'auto' | |
autoPlay | boolean | false | Won't work on most mobile devices |
loop | boolean | false | |
muted | boolean | false | |
volume | number | 1.0 | Won't work on most mobile devices |
crossOrigin | string | undefined | |
mediaGroup | string | undefined |
More native attributes detail: MDN Audio element
The controls
attribute defaults to false
and should never be changed to true
because this library is already providing UI.
Props | Type | Default | Note |
---|---|---|---|
showSkipControls | boolean | false | Show Previous/Next buttons |
showJumpControls | boolean | true | Show Rewind/Forward buttons |
showDownloadProgress | boolean | true | Show download progress over progress bar |
showFilledProgress | boolean | true | Show filled (already played) area on progress bar |
showFilledVolume | boolean | false | Show filled volume area on volume bar |
hasDefaultKeyBindings | boolean | true | Whether has default keyboard shortcuts |
autoPlayAfterSrcChange | boolean | true | Play audio after src is changed, no matter autoPlay is true or false |
volumeJumpStep | number | 0.1 | Indicates the volume jump step when pressing up/down arrow key, volume range is 0 to 1 |
progressJumpStep | number | 5000 | Deprecated, use progressJumpSteps. Indicates the progress jump step (ms) when clicking rewind/forward button or left/right arrow key |
progressJumpSteps | object | { backward: 5000, forward: 5000 } | Indicates the progress jump step (ms) when clicking rewind/forward button or left/right arrow key |
progressUpdateInterval | number | 20 | Indicates the interval (ms) that the progress bar UI updates, |
listenInterval | number | 1000 | Indicates the interval (ms) to call the onListened prop during playback |
defaultCurrentTime | ReactNode | '--:--' | Default display for audio's current time before src's meta data is loaded |
defaultDuration | ReactNode | '--:--' | Default display for audio's duration before src's meta data is loaded |
timeFormat | 'auto' | 'mm:ss' | 'hh:mm:ss' | 'auto' | Time format for both current time and duration. 'auto' means when duration is greater than one hour, time format is hh:mm:ss , otherwise it's mm:ss |
header | ReactNode | null | Header of the audio player |
footer | ReactNode | null | Footer of the audio player |
layout | 'stacked' | 'horizontal' | 'stacked-reverse' | 'horizontal-reverse' | 'stacked' | Overall layout of the audio player |
customIcons | CustomIcons | {} | Custom icons to replace the default ones |
customProgressBarSection | Array<string | ReactElement> | [CURRENT_TIME, PROGRESS_BAR, DURATION] | Custom layout of progress bar section |
customControlsSection | Array<string | ReactElement> | [ADDITIONAL_CONTROLS, MAIN_CONTROLS, VOLUME_CONTROLS] | Custom layout of controls section |
customAdditionalControls | Array<string | ReactElement> | [LOOP] | Custom layout of additional controls |
customVolumeControls | Array<string | ReactElement> | [VOLUME] | Custom layout of volume controls |
i18nAriaLabels | I18nAriaLabels | I18nAriaLabels | A configuration object to overwrite the default aria-label on the action buttons |
mse | Object | null | A configuration object so the player can play audio chunks, MSE streams and encrypted audio (See section about Media Source Extensions in this Readme) |
mse.srcDuration | number | - | The complete duration of the MSE audio chunks together (this is a key of the mse prop) |
mse.onSeek | Function (Event) | - | The callback to be used when seek happens (this is a key of the mse prop) |
mse.srcDuration | number | - | The callback to be used when encrypted audio is detected and needs to be decrypted (this is a key of the mse prop) |
Supported media events: onPlay
, onPause
, onEnded
, onSeeking
, onSeeked
, onAbort
, onCanPlay
, onCanPlayThrough
, onEmptied
, onError
, onLoadStart
, onLoadedMetaData
, onLoadedData
, onPlaying
, onSuspend
, onWaiting
, onVolumeChange
Docs: Media Events | MDN
Note: onTimeUpdate
is not supported. Please use onListen
with listenInterval
for better performance.
Props | Type | Default | Note |
---|---|---|---|
onClickPrevious | Function (Event) | null | Called when click Previous button |
onClickNext | Function (Event) | null | Called when click Next button |
onListen | Function (Event) | null | Called every listenInterval milliseconds during playback |
onPlayError | Function (Error) | null | Called when there's error invoking audio.play() , it captures error that onError won't catch |
onChangeCurrentTimeError | Function () | null | Called when dragging progress bar or press rewind/forward while the audio hasn't loaded yet |
Besides using props to change UI, React H5 Audio Player provides built-in class names and SASS/LESS variables for developers to overwrite.
1$rhap_theme-color: #868686 !default; // Color of all buttons and volume/progress indicators 2$rhap_background-color: #fff !default; // Color of the player background 3$rhap_bar-color: #e4e4e4 !default; // Color of volume and progress bar 4$rhap_time-color: #333 !default; // Font color of current time and duration 5$rhap_font-family: inherit !default; // Font family of current time and duration
For LESS variables, just replace $
with @
. This library supports both.
There are some status class names on the audio player's wrapper div. They can be used for overwriting styles.
className | Description |
---|---|
rhap_loop--on | Loop is on |
rhap_loop--off | Loop is off |
rhap_play-status--paused | Paused status |
rhap_play-status--playing | Playing status |
For example:
1.rhap_play-status--paused .rhap_progress-bar { 2 // Overwrite the progress bar style while the audio is paused 3}
You can get direct access to the underlying audio element. First get a ref to ReactAudioPlayer:
1this.player = createRef() 2 3<ReactAudioPlayer ref={this.player} />
Then you can access the audio element like this:
this.player.current.audio.current
You can use Media Source Extensions and Encrypted Media Extensions with this player. You need to provide the complete duration, and also a onSeek and onEncrypted callbacks. The logic for feeding the audio buffer and providing the decryption keys (if using encryption) must be set in the consumer side. The player does not provide that logic. Check the StoryBook example to understand better how to use.
https://github.com/lhz516/react-h5-audio-player/releases
Issues and PR's are welcome.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
3 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 2/22 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
40 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More