0.1.0 • Published 5 years ago

react-audio-spectrum v0.1.0

Weekly downloads
294
License
ISC
Repository
github
Last release
5 years ago

React Audio Spectrum

An audio spectrum visualizer for react.

npm.io

Live Demo

https://hu-ke.github.io/react-audio-spectrum/

Getting Started

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

you can also pass audio element 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

propertydescriptiontypedefaultisRequired
idcanvas idnumber/stringa random stringfalse
widthcanvas widthnumber300false
heightcanvas heightnumber200false
audioIdid of the target audio elementnumber/string-true
capColorcolor of capsstring#FFFfalse
capHeightheight of capsstring2false
meterWidthwidth of metersnumber2false
meterColorcolor of metersstring/array{stop: 0, color: '#f00'},{stop: 0.5, color: '#0CD7FD'},{stop: 1, color: 'red'}false
gapgap between metersnumber10false

Install

yarn add react-audio-spectrum --save
or
npm install react-audio-spectrum --save

Contributing

react-audio-spectrum is a free and open source react library, and I appreciate any help you're willing to give - whether it's fixing bugs, improving documentation, or suggesting new features.