Skip to content

vnglst/play-web-audio

Repository files navigation

Play Web Audio

Install

yarn add play-web-audio

Usage

import { playAudio, loadAudioUrls } from 'play-web-audio'

let squakk
const soundUrls = ['./sounds/squakk.mp3']

loadAudioUrls(this.soundUrls, bufferList => {
  squakk = bufferList[0]
})

playAudio(squakk) // plays the audio file
/*
    N.B. on many devices autoplay is not allowed. In that case the play function must be initiated by a user interaction, i.e. a mouse click or finger tap.

*/

Example

Demonstration of using the Web Audio API using React. See folder example. Try this on iPhone/Safari (iOS), playback is instant! Now compare it with the implementation using the <audio> HTML tag... long delay on iPhone.

Ergo: use the Web Audio API instead.

https://play-it.now.sh

Credits

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published