uiplay
v1.0.2
Published
Interface to play audio and other web compatible resources
Downloads
2
Readme
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-1Default: 1 | Controls the volume level for each audio object |
| throttleMillis
| Integer of millisecondsDefault: 300 | Throttle time for the next play |
| ignoreErrors
| BooleanDefault: true | Ignore or throw errors. Errors must be catched if throwning |