audio-playerx
Core audio player in the browser
Installation
npm install audio-playerx
or
yarn add audio-playerx
Usage
audio-playerx support two modes.
HTMLAudioElement
; // initializationconst player = mode: PLAYER_MODEAudio { console; }; // play your audioplayer; // pauseplayer; // play continueplayer;
Web Audio API
; // initializationconst player = mode: PLAYER_MODEAudioContext { console; }; // play your audioplayer; // stopplayer; // close playerplayer;
API
AudioPlayer
; ; // is equal to mode: PLAYER_MODEAudio ;
- Support play, pause and resume
Constructor
new = : AudioPlayer;
onStateChange is a callback, called when the player state changes.
;
Methods
play:Promise<PLAYER_STATE | undefined>
audio play and resume.
When the parameter 'resource' is passed, it will start playing from the beginning, otherwise it is used to continue playing the paused audio.
pause:void
ACTXPlayer
; ; // is equal to mode: PLAYER_MODEAudioContext ;
- Only supports play, stop
- doesn't support pause, resume
Constructor
new = : AudioPlayer;
onStateChange is a callback, called when the player state changes.
;
Methods
play:Promise<PLAYER_STATE | undefined>,
stop:void
close:void
PLAYER_MODE
player mode enum
Audio: 0 AudioContext: 1
PLAYER_STATE
player state enum
READY: 0 LOADING: 1 PLAYING: 2 PAUSED: 3 FAILED: 4 DESTROYED: 5