uiplay

1.0.2 • Public • Published

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

Option Accepts Description
volume Float fraction between 0-1
Default: 1
Controls the volume level for each audio object
throttleMillis Integer of milliseconds
Default: 300
Throttle time for the next play
ignoreErrors Boolean
Default: true
Ignore or throw errors. Errors must be catched if throwning

License

MIT License

Readme

Keywords

Package Sidebar

Install

npm i uiplay

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

42.9 kB

Total Files

8

Last publish

Collaborators

  • clytras