
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
react-h5-audio-player
Advanced tools
A React audio player with UI. Written in TypeScript. Mobile compatible. Keyboard friendly
Live Demo: Storybook
Website example: hanzluo.com | Code
Supported browsers: Chrome, Firefox, Safari, Opera, Edge, IE (≥10)
$ npm i react-h5-audio-player
Or
$ yarn add react-h5-audio-player
import AudioPlayer from 'react-h5-audio-player';
import 'react-h5-audio-player/lib/styles.css';
// import 'react-h5-audio-player/lib/styles.less' Use LESS
// import 'react-h5-audio-player/src/styles.scss' Use SASS
const Player = () => (
<AudioPlayer
autoPlay
src="http://example.com/audio.mp3"
onPlay={e => console.log("onPlay")}
// other props here
/>
);
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 | string | 'auto' | |
autoPlay | boolean | false | Won't work on mobile |
loop | boolean | false | |
muted | boolean | false | |
loop | boolean | false | |
volume | number | 1.0 | Won't work on mobile |
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 |
---|---|---|---|
showVolumeControl | boolean | true | Show volume bar and mute button |
showLoopControl | boolean | true | Show loop toggle button |
showSkipControls | boolean | false | Show Previous/Next buttons |
showJumpControls | boolean | true | Show Rewind/Forward buttons |
showDownloadProgress | boolean | true | Show download progress over progress bar |
onClickPrevious | Function (Event) | null | Called when click Previous button |
onClickNext | Function (Event) | null | Called when click Next button |
onPlayError | Function (Error) | null | Called when there's error invoking audio.play() , it captures error that onError won't catch |
volumeJumpStep | number | 0.1 | Indicates the volume jump step when pressing up/down arrow key, volume range is 0 to 1 |
progressJumpStep | number | 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 |
onListen | Function (number) | null | Called every listenInterval milliseconds during playback |
onPlay | Function (Event) | null | Called when user plays the audio |
onPause | Function (Event) | null | Called when user pauses the audio |
onAbort | Function (Event) | null | Called when unloading the audio player, like when switching to a different src file |
onCanPlay | Function (Event) | null | Called when enough of the file has been downloaded to be able to start playing |
onCanPlayThrough | Function (Event) | null | Called when enough of the file has been downloaded to play through the entire file |
onEnded | Function (Event) | null | Called when playback has finished to the end of the file |
onError | Function (Event) | null | Called when the audio tag encounters an error |
React H5 Audio Player provides built-in class names and SASS/LESS variables for developers to overwrite.
$rhap_theme-color: #868686 !default;
$rhap_background-color: #fff !default;
$rhap_bar-color: #e4e4e4 !default;
$rhap_time-color: #333 !default;
$rhap_font-family: inherit !default;
For LESS variables, just replace $
with @
.
You can get direct access to the underlying audio element. First get a ref to ReactAudioPlayer:
<ReactAudioPlayer ref={c => (this.player = c)} /> // Using `createRef` also works
Then you can access the audio element like this:
this.player.audio
https://github.com/lhz516/react-h5-audio-player/releases
css
, scss
or less
manuallyhidePlayer
- Use parent logic to hide playeronDragStart
, onDragMove
, onDragEnd
- V2 isn't using drag events anymoreIn 1.x, we use prop-types
package instead of using it directly in React. Thus we dropped support under react@15.5.0
. The usage will remain the same.
Issues and PR's are welcome.
FAQs
A customizable React audio player. Written in TypeScript. Mobile compatible. Keyboard friendly
The npm package react-h5-audio-player receives a total of 40,108 weekly downloads. As such, react-h5-audio-player popularity was classified as popular.
We found that react-h5-audio-player demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.