1.2.4 • Published 10 months ago

react-audio-player-component v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

react-audio-player-component

A mobile-friendly audio player for React with a modern look and convenient usage.

NPM downloads Run ESlint Run Unit tests Run Unit tests

Installation

npm install react-audio-player-component

AudioPlayer Component (Example)

screenshot screenshot Minimal Audio player

import React, { useState } from 'react';
import { AudioPlayer } from 'react-audio-player-component';

const Player = () => {
  return (
    <AudioPlayer 
      src="audios/test.mp3"
      minimal={false}
      width={350}
      trackHeight={75}
      barWidth={1}
      gap={1}

      visualise={true}
      backgroundColor="#FFF8DE"
      barColor="#C1D0B5"
      barPlayedColor="#99A98F"

      skipDuration={2}
      showLoopOption={true}
      showVolumeControl={true}

      // seekBarColor="purple"
      // volumeControlColor="blue"
      // hideSeekBar={true}
      // hideTrackKnobWhenPlaying={true}
    />
  )
}

Audio element native props

PropsDescriptionDefaultOptional
srcThe address or URL of the a audio resource that is to be consideredN/ANo
volumeInitial volume level for the audio, minimum being 0, maximum being 10.75Yes
loopSets a flag to specify whether playback should restart after it completesfalseYes
mutedSets a flag that indicates whether the audio is mutedfalseYes
autoplaySets a value that indicates whether to start playing the media automaticallyfalseYes
crossOriginThe CORS setting for this media element. MDN ReferencenullYes
autoplaySets a value indicating what data should be preloaded, if any. Allowed values "", "none", "metadata", "auto"""Yes
playbackRateSets the rate at which media is being played back1.0Yes

Audio element events

AudioPlayer supports all the events for HTMLMediaElement (MDN Reference). All of the events listed in the MDN docs can be passed as a prop to the AudioPlayer


Audio player props

PropsDescriptionDefaultOptional
minimalDisplays a minimal version of the audio player, with only the play/pause button, track bar and timestampfalseYes
widthWidth of the audio playerN/ANo
barWidthWidth of each individual bar in the visualization2Yes
gapGap between each bar in the visualization1Yes
visualiseRepresents whether the audio visualization (waveform) should be displayedtrueYes
trackHeightHeight of the visualization / trackbar area75Yes
backgroundColorBackground color for the audio player#EFEFEFYes
barColorColor for the bars in the visualization. This only applies to bars that have not currently been played"rgb(184, 184, 184)""Yes
barPlayedColorColor for the bars that have been played"rgb(160, 198, 255)""Yes
allowSkipRepresents whether the skip forward/backward options should be displayedtrueYes
skipDurationThe number of seconds to skip forward/backward5Yes
showLoopOptionRepresents whether to show the loop optionstrueYes
showVolumeControlRepresents whether the volume control should be showntrueYes
seekBarColorColor for the audio seek barrgba(140, 140, 140)Yes
volumeControlColorColor for the volumn controlrgba(140, 140, 140)Yes
hideSeekBarHides the seek bar if set to true, the audio will still be seekablefalseYes
hideSeekKnobWhenPlayingHides the seek knob when audio is playing if set to truefalseYes