Gathering detailed insights and metrics for react-howler
Gathering detailed insights and metrics for react-howler
Gathering detailed insights and metrics for react-howler
Gathering detailed insights and metrics for react-howler
npm install react-howler
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
362 Stars
113 Commits
83 Forks
7 Watching
67 Branches
20 Contributors
Updated on 23 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-25%
1,140
Compared to previous day
Last week
-9.2%
5,837
Compared to previous week
Last month
2.8%
26,313
Compared to previous month
Last year
4.4%
288,963
Compared to previous year
A React.js wrapper for howler.js (audio player).
ReactHowler has no UI, you have 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
1import React, { Component } from 'react' 2import ReactHowler from 'react-howler' 3 4class App extends Component { 5 // This sound file may not work due to cross-origin setting 6 render () { 7 return ( 8 <ReactHowler 9 src='http://goldfirestudios.com/proj/howlerjs/sound.ogg' 10 playing={true} 11 /> 12 ) 13 } 14}
For a full working example please see it in App.js
http://khoanguyen.me/react-howler/ or
1git clone http://github.com/thangngoc89/react-howler 2npm install 3npm run example:react 4open http://localhost:3000
Prop | Default | Description |
---|---|---|
src | The sources to the track(s) to be loaded for the sound (URLs or base64 data URIs). These should be in order of preference, howler.js will automatically load the first one that is compatible with the current browser. If your files have no extensions, you will need to explicitly specify the extension using the format property. Updating the src prop on the fly will destroy any currently playing howler instance and create a new one with the new src . Updating other props while keeping the src the same will maintain the current howler instance. | |
preload | true | Set to true to begin downloading the audio file if it is not loaded yet. |
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 |
rate | 1 | The initial playback rate (speed) |
html5 | false | Set to true to force HTML5 Audio. This should be used for large audio files so that you don't have to wait for the full file to be downloaded and decoded before playing. |
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). |
xhr | {} | When using Web Audio, howler.js uses an XHR request to load the audio files. If you need to send custom headers, set the HTTP method or enable withCredentials (see reference), include them with this parameter. Each is optional (method defaults to GET , headers default to null and withCredentials defaults to false ). For example:
|
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 |
onSeek | noop | Called when the sound has been seeked. The first parameter is the ID of the sound. onSeek(id) |
onPlayError | noop | Called when the sound is unable to play. The first parameter is the ID of the sound and the second is the error message/code. onPlayError(id, errorCode) |
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.When preload
is true
this is automatically called. When setting preload
to false
, you can call load()
manually before playing sounds (useful for lazy loading large files on slow networks). If you attempt to play a sound that's not loading or loaded with preload react-howler will automatically call load()
.
Tip: If you're calling load()
manually, check the load status with howlerState()
Get/set the position of playback for a sound.
Number
optional
The position to move current playback to (in seconds).Check the load status of the Howl
, returns a string unloaded
, loading
or loaded
.
This is an alias for Howler's state()
function
Stops playback of sound, resetting seek
to 0
.
Number
optional
The sound ID. If none is passed, all sounds in group are stopped.Speeds up/down an audio playback. Calling with no arguments will reset all howls to default rate.
Number
optional
The playback rate. If empty, will default to 1
.Number
optional
The sound ID. If empty, all sounds in group get updated.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
1import React, { Component } from 'react' 2import ReactHowler from 'react-howler' 3 4class App extends Component { 5 getHowler () { 6 this.player.howler 7 } 8 9 getDuration () { 10 this.player.duration() 11 } 12 13 getSeek () { 14 this.player.seek() 15 } 16 17 setSeek () { 18 this.player.seek(0.5) 19 } 20 // This sound file may not work due to cross-origin setting 21 render () { 22 return( 23 <ReactHowler 24 src='http://goldfirestudios.com/proj/howlerjs/sound.ogg' 25 playing={true} 26 ref={(ref) => (this.player = ref)} 27 /> 28 ); 29 } 30}
Howler global methods are avaiable in window scope. Please refer to howler's documentation
Usage:
1window.Howler.mute(true) // Mute all sounds
This project uses standard code style.
npm run lint
sound.ogg
Taken from howler.js demo page Sound file direct link: sound.ogg
sound2.ogg
Fingerstyle Bass line over an Am chord progression By Serolillo (Own work) [CC BY 2.5 (http://creativecommons.org/licenses/by/2.5)], via Wikimedia Commons
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/28 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
124 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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