You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-howler

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-howler

A React.js wrapper for howler.js (audio player)

2.0.0
Source
npmnpm
Version published
Weekly downloads
6.1K
2.93%
Maintainers
1
Weekly downloads
 
Created
Source

react-howler

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, ...

Travis status LICENSE MIT js-standard-style npm dependencies

howler.js

howler.js is an audio library for the modern web. It defaults to Web Audio API and falls back to HTML5 Audio.

Currently, I'm tracking branch 2.0 beta because

the core is fairly stable and is already under heavy production use.

Usage

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 () {
    <ReactHowler
      src='http://goldfirestudios.com/proj/howlerjs/sound.ogg'
      playing={true}
    />
  }
}

For a full working example please see it in App.js

Demo

http://khoanguyen.me/react-howler/ or

git clone http://github.com/thangngoc89/react-howler
npm install
npm run example:react
open http://localhost:3000

Props

PropDefaultDescription
srcThe src of songs for playing. Can be a string or an array
playingtrueSet to true or false to pause or play the media. This also invoke autoplay on initial load
loopfalseSet to true or false to enable/disable loop
mutefalseSet to true or false to mute/unmute current audio
onPlaynoopCalled when audio starts or resumes playing
onPausenoopCalled when audio is paused
onLoadnoopCalled when audio is loaded (buffered)
onLoadErrornoopCalled when an error occurs whilst attempting to load media
onEndnoopCalled when media finishes playing

Methods

  • seek(pos? : Number) Set/get current position of player
  • duration: Get duration of current audio file

I only wrapper methods that I need. If you need to use undocumented methods, you can access howler instance directly via howler method

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 () {
    <ReactHowler
      src='http://goldfirestudios.com/proj/howlerjs/sound.ogg'
      playing={true}
      ref={(ref) => this.audio = ref}
    />
  }
}

Howler global core method

Howler global methods is avaiable in window scope. Please refer to howler's documentation

Usage:

window.Howler.mute(true) // Mute all sounds

Linting

This project uses standard code style.

js-standard-style

npm run lint

Audio file in examples

I take it from howler.js demo page

Sound file direct link: sound.ogg

License

MIT

Keywords

react-component

FAQs

Package last updated on 05 Feb 2016

Did you know?

Socket

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.

Install

Related posts