@yandeu/audio
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

🎵 Audio

Audio library for the Web Audio API.
(TypeScripted version of Three.js@r126's Audio without Object3D)

Installation

npm install @yandeu/audio

CDN

https://unpkg.com/@yandeu/audio/umd/audio.min.js

Usage

// import AudioManager
import { AudioManager } from '@yandeu/audio'

// print the current version
console.log('AudioManager VERSION: ', AudioManager.VERSION)

// instantiate
const audio = new AudioManager()

// load your sound: Promise<void>
// (Loads either dance-hits-2011.mp3 or dance-hits-2011.ogg depnding on browser support.)
await audio.load('hits', '../sound/dance-hits-2011', 'mp3', 'ogg')

// create your sound: Promise<Sound>
const sound = await audio.add('hits')

// play your sound
sound.play()

// check if your sound is playing
sound.isPlaying

// pause your sound (resume with .play())
sound.pause()

// stop your sound
sound.stop()

// and many many more...

Transpile

You probably need something like babel to make this library work on older devices.

Apple iOS

On a newly-created AudioContext will always begin in the suspended state. Resume the state on a user event.

const audioManager = new AudioManager()

window.addEventListener(
  'click',
  async () => {
    await audioManager.listener.context.resume()
    // now you can play your audio
  },
  { once: true }
)

API

You will find the full API on https://yandeu.github.io/audio.
The most important classes are AudioManager and Audio.

Related Packages

Package Description
audio 🎵 Audio library for the Web Audio API.
keyboard ⌨️ Handling of keyboard events.
tap 🖱️ Handling of user interactions such as mouse, touch and pointer events.

Questions?

Join the enable3d discussions!

License

MIT

Package Sidebar

Install

npm i @yandeu/audio

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

178 kB

Total Files

43

Last publish

Collaborators

  • yandeu