JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q42447F
  • License MIT

ClickTone is designed to control audio playback with various settings, including volume control, callback and debug mode. It also includes iOS support.

Package Exports

  • clicktone

Readme


clicktone

npm GitHub package version NPM Downloads

ClickTone is designed to control audio playback with various settings, including volume control, callback and debug mode. It also includes iOS support.

1kB gzipped

Demo


Install

yarn add clicktone

Import

import ClickTone from 'clicktone';

Usage

ClickTone uses the Web Audio API, which supports many audio file formats: MP3, WAV, OGG, AAC and others. Note that not all browsers support these formats.

const sound = new ClickTone({
  // file: './sound.mp3',
  file: new URL('./sound.mp3', import.meta.url).href,
  volume: 0.7,
  throttle: 100,
  callback: () => { console.log('Playback ended') },
  debug: true,
});

const play = () => sound.play();

button.addEventListener('pointerdown', play);

Options

Option Type Default Description
file string none The URL of the audio file to be played.
volume number 1.0 Volume level for the audio playback, ranging from 0.0 (mute) to 1.0 (full volume).
callback ((error?: Error) => void) | null null A callback function to be executed after the audio finishes playing, or if an error occurs.
throttle number 0 Minimum time (in milliseconds) between successive audio plays to prevent rapid repeat plays.
debug boolean false If true, debug information and errors will be logged to the console.

License

clicktone is released under MIT license.