Home

Awesome

react-sound

npm version

Sound component to play audio in your web apps. Backed by the mighty soundmanager2 library.

Example

// In your React component:
render() {
  return (
    <Sound
      url="cool_sound.mp3"
      playStatus={Sound.status.PLAYING}
      playFromPosition={300 /* in milliseconds */}
      onLoading={this.handleSongLoading}
      onPlaying={this.handleSongPlaying}
      onFinishedPlaying={this.handleSongFinishedPlaying}
    />
  );
}

Sound as a component?

Yes! It's really easy to use sounds in your app as part of the component tree in your React app.

How to install

npm install react-sound --save

How to use

var React = require('react');
var Sound = require('react-sound').default;

// ... or using import:
import React from 'react';
import Sound from 'react-sound';

class MyComponentWithSound extends React.Component {
  render() {
    return <Sound {...props} />; // Check props in next section
  }
}

Note: By default, a restriction on mobile prevent you from playing multiple sounds. To avoid this, you need to set the ignoreMobileRestrictions property to true when setting up soundManager2.

Props

How to contribute

Feel free to fork and send PRs or issues, be it for features, bug fixes, or documentation!