
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
react-howler
Advanced tools
A React.js wrapper for howler.js (audio player).
ReactHowler has no UI. You has to provide your own UI
Props can be passed to control playback and react to events such as end, load, play, ...
howler.js is an audio library for the modern web. It defaults to Web Audio API and falls back to HTML5 Audio.
npm install --save react-howler
import React, { Component } from 'react'
import ReactHowler from 'react-howler'
class App extends Component {
// This sound file may not work due to cross-origin setting
render () {
return (
<ReactHowler
src='http://goldfirestudios.com/proj/howlerjs/sound.ogg'
playing={true}
/>
)
}
}
For a full working example please see it in App.js
http://khoanguyen.me/react-howler/ or
git clone http://github.com/thangngoc89/react-howler
npm install
npm run example:react
open http://localhost:3000
Prop | Default | Description |
---|---|---|
src | The src of songs for playing. Can be a string or an array | |
playing | true | Set to true or false to pause or play the media.Setting to true on initial load will play the audio immediately after it is loaded |
loop | false | Set to true or false to enable/disable loop |
mute | false | Set to true or false to mute/unmute current audio |
volume | 1.0 | The volume of the specific howl, from 0.0 to 1.0 |
format | [] | howler.js automatically detects your file format from the extension, but you may also specify a format in situations where extraction won't work (such as with a SoundCloud stream). |
onPlay | noop | Called when audio starts or resumes playing |
onPause | noop | Called when audio is paused |
onVolume | noop | Called when volume is changed |
onStop | noop | Called when audio is stopped |
onLoad | noop | Called when audio is loaded (buffered) |
onLoadError | noop | Called when an error occurs whilst attempting to load media |
onEnd | noop | Called when media finishes playing |
Get the duration of the audio source. Will return 0 until after the load
event fires.
Number
optional
The sound ID to check. Passing an ID will return the duration of the sprite being played on this instance; otherwise, the full source duration is returned.Get/set the position of playback for a sound.
Number
optional
The position to move current playback to (in seconds).Stops playback of sound, resetting seek
to 0
.
Number
optional
The sound ID. If none is passed, all sounds in group are stopped.If you need to use other howler.js methods
that are not included in this wrapper you can access the howler instance directly via howler
import React, { Component } from 'react'
import ReactHowler from 'react-howler'
class App extends Component {
getHower () {
this.audio.howler
}
getDuration () {
this.audio.duration()
}
getSeek () {
this.audio.seek()
}
setSeek () {
this.audio.seek(0.5)
}
// This sound file may not work due to cross-origin setting
render () {
return(
<ReactHowler
src='http://goldfirestudios.com/proj/howlerjs/sound.ogg'
playing={true}
ref={(ref) => this.audio = ref}
/>
);
}
}
Howler global methods are avaiable in window scope. Please refer to howler's documentation
Usage:
window.Howler.mute(true) // Mute all sounds
This project uses standard code style.
npm run lint
Taken from howler.js demo page
Sound file direct link: sound.ogg
MIT
3.4.1 - 2017-01-19
FAQs
A React.js wrapper for howler.js (audio player)
The npm package react-howler receives a total of 4,612 weekly downloads. As such, react-howler popularity was classified as popular.
We found that react-howler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.