1.0.2 • Published 4 years ago

uiplay v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

npm.io

UIPlay

This is a small utility that preloads audio files and lets developers to play them at any point they need to. This utility properly cacthes all corecponding errors that may occur during loading and playback. It forces browser to preload files by appending HTML elements for each object that is initialized.

Demo

You can find an online demo here: https://lytrax.io/pub/dev/uiplay

Installation

NPM: npm install uiplay --save Yarn: yarn add uiplay Browser: Download latest release from releases, or browse JSDeliver CDN to pick the latest version.

<script src='uiplay.js'></script>

Usage

import UIPlay from 'uiplay';

const NofifyAudio = new UIPlay(
  'orders_notify.mp3',
  {
    volume: 1
  }
);

document.getElementById('play-audio').addEventListener('click', () => {
  NofifyAudio.play();
});

Methods

UIPlay(file: string, options: object) (contructor) The initialization of a new HTMLMediaElement object.

play(volume: number) Plays the audio using a throtte timer. The volume parameter can be omitted to use options volume.

playImmediate(volume: number) Plays the audio immediately without throtte. The volume parameter can be omitted to use options volume.

setVolume(volume: number) Sets the volume level using decimal fraction (0-1).

NOTE: All methods return the actual object.

Options

OptionAcceptsDescription
volumeFloat fraction between 0-1Default: 1Controls the volume level for each audio object
throttleMillisInteger of millisecondsDefault: 300Throttle time for the next play
ignoreErrorsBooleanDefault: trueIgnore or throw errors. Errors must be catched if throwning

License

MIT License