0.2.0 • Published 2 years ago

react-av v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Audio Spectrum

An audio spectrum visualizer for react.

Getting Started

<audio id="audio-element"
  src="path/to/song.mp3"
  controls
>
</audio>
<AudioSpectrum
  id="audio-canvas"
  height={200}
  width={300}
  audioId={'audio-element'}
  capColor={'red'}
  capHeight={2}
  meterWidth={2}
  meterCount={512}
  meterColor={[
    {stop: 0, color: '#4CAF40'},
    {stop: 0.5, color: '#0CD7FD'},
    {stop: 1, color: '#000'}
  ]}
  gap={4}
/>

you can also pass the audio element itself to the component

this.audioEle = new Audio('path/to/your/song.mp3')
<AudioSpectrum
  id="audio-canvas"
  height={200}
  width={300}
  audioEle={this.audioEle}
/>

if you use both audioId and audioEle props, the component will ignore audioEle.

Props

propertydescriptiontypedefault
idcanvas idnumber/stringa random string
widthcanvas widthnumber300
heightcanvas heightnumber200
audioIdid of the target audio elementnumber/string-
audioEletarget audio elementaudio object-
capColorcolor of capsstring#FFF
capHeightheight of capsstring2
disableCapshows or hides capsbooleanfalse
meterWidthwidth of metersnumber2
meterColorcolor of metersstring/array{stop: 0, color: '#f00'},{stop: 0.5, color: '#0CD7FD'},{stop: 1, color: 'red'}
gapgap between metersnumber10
fftSizewindow size in samplesnumber2048 (must be between 32-32768 & a power of 2)
smoothingTimeConstantaveraging constant with the last analysis framenumber0.8 (must be between 0-1)