https://github.com/audiojs/audio-play
Play audio buffer in browser/node
https://github.com/audiojs/audio-play
Last synced: 8 months ago
JSON representation
Play audio buffer in browser/node
- Host: GitHub
- URL: https://github.com/audiojs/audio-play
- Owner: audiojs
- License: mit
- Created: 2016-09-09T23:44:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-22T02:33:13.000Z (about 5 years ago)
- Last Synced: 2025-08-20T02:55:22.416Z (10 months ago)
- Language: JavaScript
- Size: 2.47 MB
- Stars: 60
- Watchers: 10
- Forks: 14
- Open Issues: 14
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# audio-play [](https://travis-ci.org/audiojs/audio-play) [](http://github.com/badges/stability-badges) [](https://greenkeeper.io/)
Play [audio buffer](https://github.com/audiojs/audio-buffer), browser/node-wise.
## Usage
[](https://npmjs.org/package/audio-play/)
```js
const play = require('audio-play');
const load = require('audio-loader');
load('./sample.mp3').then(play);
```
## API
```js
const play = require('audio-play');
//play audio buffer with possible options
let pause = play(audioBuffer, {
//start/end time, can be negative to measure from the end
start: 0,
end: audioBuffer.duration,
//repeat playback within start/end
loop: false,
//playback rate
rate: 1,
//fine-tune of playback rate, in cents
detune: 0,
//volume
volume: 1,
//device (for use with NodeJS, optional)
device: 'hw:1,0',
//possibly existing audio-context, not necessary
context: require('audio-context'),
//start playing immediately
autoplay: true
}, onend?);
//pause/continue playback
play = pause();
pause = play();
//or usual way
let playback = play(buffer, opts?, cb?);
playback.pause();
playback.play();
//get played time
playback.currentTime;
```
### Related
* [audio-loader](https://github.com/audiojs/audio-loader) — load AudioBuffer from any audio source.
* [audio-decode](https://github.com/audiojs/audio-decode) — decode audioBuffer