1.0.12 • Published 5 months ago

audio-visualiser v1.0.12

Weekly downloads
4
License
MIT
Repository
github
Last release
5 months ago

<audio-visualiser>

FFT Audio Analyser visuals ready for retina displays.

Note: Uses ResizeObserver. Polyfill it on your end.

API

Inputs

MethodDescriptionRelated media event
set analyserSet analyser to read data from.
start()Start the visuals drawing loop.play
stop()Stop the visuals drawing loop.pause / ended
AttributeDescription
colorSets the color of the visual.

Usage

Install audio-visualiser via npm or import it in your ES module supported browser with import 'https://cdn.skypack.dev/audio-visualiser';

Create an AnalyserNode and connect it to by calling the setter analyser on the instance of the custom element. document.querySelector('audio-visualiser').analyser = yourAnalyserNode;. For a little live demo of this you can check out https://enjikaka.github.io/audio-visualiser/. Open dev tools or view-source to see how the tag is set up to the analyser via createMediaElementSource.

<audio id="audio" src="worth-fighting-for.mp3" controls></audio>
<audio-visualiser id="visuals" color="rebeccapurple"></audio-visualiser>
import 'https://cdn.skypack.dev/audio-visualiser';

const audio = document.getElementById('audio');
const visuals = document.getElementById('visuals');

audio.currentTime = 41;

const audioContext = new AudioContext();

const source = audioContext.createMediaElementSource(audio);
const analyser = audioContext.createAnalyser();

analyser.fftSize = 1024;

source.connect(analyser);
analyser.connect(audioContext.destination);

visuals.analyser = analyser;

audio.addEventListener('play', () => {
  audioContext.resume();
  console.log('playing');
  visuals.start();
});

audio.addEventListener('pause', () => {
  console.log('paused');
  visuals.stop();
});
1.0.8

5 months ago

1.0.11

5 months ago

1.0.12

5 months ago

1.0.2

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

6 years ago

1.0.0

6 years ago