1.2.0 • Published 6 years ago

audio-playerx v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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

import Playerx, { PLAYER_STATE, PLAYER_MODE } from "audio-playerx";

// initialization
const player = new Playerx({
  mode: PLAYER_MODE.Audio,
  onStateChange(value) {
    console.log(value);
  }
});

// play your audio
player.play(resource: string);

// pause
player.pause();

// play continue
player.play();

Web Audio API

import Playerx, { PLAYER_STATE, PLAYER_MODE } from "audio-playerx";

// initialization
const player = new Playerx({
  mode: PLAYER_MODE.AudioContext,
  onStateChange(value) {
    console.log(value);
  }
});

// play your audio
player.play(buffer: ArrayBuffer);

// stop
player.stop();

// close player
player.close();

API

AudioPlayer

import { AudioPlayer } from "audio-playerx";

new AudioPlayer();

// is equal to

new Playerx({ mode: PLAYER_MODE.Audio });
  • Support play, pause and resume

Constructor

new ({ onStateChange?: onStateChange } = {}): AudioPlayer;

onStateChange is a callback, called when the player state changes.

type onStateChange: (value: PLAYER_STATE) => any;

Methods

play: (resource: string | undefined) => 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

import { ACTXPlayer } from "audio-playerx";

new ACTXPlayer();

// is equal to

new Playerx({ mode: PLAYER_MODE.AudioContext });
  • Only supports play, stop
  • doesn't support pause, resume

Constructor

new ({ onStateChange?: onStateChange } = {}): AudioPlayer;

onStateChange is a callback, called when the player state changes.

type onStateChange: (value: PLAYER_STATE) => any;

Methods

play: (buffer: ArrayBuffer) => 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,
}
1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

1.0.0-1

6 years ago

1.0.0-0

6 years ago

0.1.0

6 years ago