# uiplay

> Interface to play audio and other web compatible resources

Latest version **1.0.2** (published 2019-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install uiplay
pnpm add uiplay
yarn add uiplay
bun add uiplay
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-11-14 |
| First published | 2019-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 41.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Christos Lytras |
| Maintainers | clytras |
| Keywords | play, audio, utility, html5 |

## Links

- npm: https://www.npmjs.com/package/uiplay
- Repository: https://github.com/clytras/UIPlay
- Homepage: https://github.com/clytras/UIPlay#readme
- Issues: https://github.com/clytras/UIPlay/issues
- npm.io page: https://npm.io/package/uiplay

## Dependencies (1)

- [throttle-debounce](https://npm.io/package/throttle-debounce.md) ^2.1.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-11-14
- 1.0.1 — 2019-11-14
- 1.0.0 — 2019-11-14

## README

<p align="center">
  <img height="120" src="uiplay-logo.png">
</p>

[![](https://data.jsdelivr.com/v1/package/npm/uiplay/badge)](https://www.jsdelivr.com/package/npm/uiplay)

# 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:<br>
`npm install uiplay --save`<br><br>
Yarn:<br>
`yarn add uiplay`<br><br>
Browser:<br>
Download latest release from [releases](https://github.com/clytras/UIPlay/releases), or browse [JSDeliver](https://www.jsdelivr.com/package/npm/uiplay) 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`)<br>
The initialization of a new HTMLMediaElement object.

`play(volume: number)`<br>
Plays the audio using a throtte timer. The `volume` parameter can be omitted to use `options` volume.

`playImmediate(volume: number)`<br>
Plays the audio immediately without throtte. The `volume` parameter can be omitted to use `options` volume.

`setVolume(volume: number)`<br>
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<br><sup>Default: 1</sup> | Controls the volume level for each audio object |
| `throttleMillis` | Integer of milliseconds<br><sup>Default: 300</sup> | Throttle time for the next play |
| `ignoreErrors` | Boolean<br><sup>Default: true</sup> | Ignore or throw errors. Errors must be catched if throwning |

## License

[MIT License](LICENSE)

---
_Source: https://npm.io/package/uiplay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
