react-audio-player vs react-h5-audio-player
React Audio Player Libraries
react-audio-playerreact-h5-audio-player

React Audio Player Libraries

React audio player libraries provide pre-built components that facilitate the integration of audio playback functionality into React applications. They simplify the process of adding audio features, allowing developers to focus on building their applications without needing to handle the complexities of the HTML5 audio API directly. These libraries often come with customizable UI components, event handling, and support for various audio formats, enhancing user experience and interaction with audio content.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-audio-player0599-675 years agoMIT
react-h5-audio-player0692338 kB27a month agoMIT

Feature Comparison: react-audio-player vs react-h5-audio-player

Customization

  • react-audio-player:

    react-audio-player provides a simple API for customization, allowing developers to easily style the player using CSS. It supports basic controls like play, pause, and volume adjustment, making it suitable for projects that require a minimalistic design.

Features

  • react-audio-player:

    react-audio-player focuses on essential audio playback features, including play/pause controls, volume adjustment, and track progress. It is designed for developers who want a no-frills approach to audio playback without additional complexities.

Complexity

  • react-audio-player:

    react-audio-player is less complex and easier to integrate into projects, making it a good choice for developers who prefer a straightforward solution without the need for extensive configuration.

UI Components

  • react-h5-audio-player:

    react-h5-audio-player offers a more feature-rich UI with customizable components, including playlists and advanced controls, making it suitable for applications that require a more interactive audio experience.

Extensibility

  • react-h5-audio-player:

    react-h5-audio-player is designed with extensibility in mind, allowing developers to easily add custom functionalities and integrate with other libraries, making it a better choice for complex applications that require additional features.

How to Choose: react-audio-player vs react-h5-audio-player

  • react-audio-player:

    Choose react-audio-player if you need a lightweight, straightforward audio player that offers basic functionality with minimal setup. It is ideal for projects where simplicity and ease of use are priorities.

README for react-audio-player

React Audio Player

This is a light React wrapper around the HTML5 audio tag. It provides the ability to manipulate the player and listen to events through a nice React interface.

Installation

npm install --save react-audio-player

Also be sure you have react and react-dom installed in your app at version 15 or above.

Usage

import ReactAudioPlayer from 'react-audio-player';
//...
<ReactAudioPlayer
  src="my_audio_file.ogg"
  autoPlay
  controls
/>

Example

See the example directory for a basic working example of using this project. To run it locally, run npm install in the example directory and then npm start.

Props

Props - Native/React Attributes

See the audio tag documentation for detailed explanations of these attributes.

PropTypeDefaultNotes
autoPlayBooleanfalse---
childrenElementnull---
classNameStringempty string---
controlsBooleanfalse---
crossOriginStringempty stringSee MDN's article on CORS for more about this attribute.
controlsListStringempty stringFor Chrome 58+. Only available in React 15.6.2+
idStringempty string---
loopBooleanfalse---
mutedBooleanfalse---
volumeNumber1.0---
preloadString'metadata'---
srcStringempty string---
styleObject------

Props - Events

PropTypeDescription
listenIntervalNumberIndicates how often to call the onListened prop during playback, in milliseconds. Default is 10000.
onAbortFunctioncalled when unloading the audio player, like when switching to a different src file. Passed the event.
onCanPlayFunctioncalled when enough of the file has been downloaded to be able to start playing. Passed the event.
onCanPlayThroughFunctioncalled when enough of the file has been downloaded to play through the entire file. Passed the event.
onEndedFunctioncalled when playback has finished to the end of the file. Passed the event.
onErrorFunctioncalled when the audio tag encounters an error. Passed the event.
onListenFunctioncalled every listenInterval milliseconds during playback. Passed the event.
onPauseFunctioncalled when the user pauses playback. Passed the event.
onPlayFunctioncalled when the user taps play. Passed the event.
onSeekedFunctioncalled when the user drags the time indicator to a new time. Passed the event.
onVolumeChangedFunctioncalled when the user changes the volume, such as by dragging the volume slider
onLoadedMetadataFunctioncalled when the metadata for the given audio file has finished downloading. Passed the event.

Advanced Usage

Access to the audio element

You can get direct access to the underlying audio element. First get a ref to ReactAudioPlayer:

<ReactAudioPlayer
  ref={(element) => { this.rap = element; }}
/>

Then you can access the audio element like this:

this.rap.audioEl

This is especially useful if you need access to read-only attributes of the audio tag such as buffered and played. See the audio tag documentation for more on these attributes.