0.7.5 • Published 7 years ago

ongaku v0.7.5

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

ongaku

A helper module for using the Web Audio API as an audio file player.

Current state.

On development. Currently only works on browsers that support AudioContext / WebkitAudioContext. Support for <audio> tag upcoming.

Installation

$ npm install ongaku

If you don't want to use npm, you can grab the browser global version from here.

Usage

import Ongaku from 'ongaku';

const opts = {
  onPlaybackEnd: function() {
    console.log('ended');
  },
  volume: 50,
};

const ongaku = new Ongaku(opts);
ongaku.playAudio('/sample/path/to/my-audio.mp3');

Supported methods.

  • playAudio(fileUrl: string) // url of the file to play
  • play()
  • pause()
  • stop()
  • seek(time: number) // destination time in ms
  • seekPercentage(percentage: number) // 0 - 100
  • setVolume(volumeLevel: number) // 0 - 100
  • mute()
  • unmute()
  • getPlaybackTime() // current track playing time (in seconds)
  • isPlaying() // Current playback status

Supported options

{ volume: number // The default volume, 0-100
, onPlaybackStart: () => void // Called when buffer starts playing
, onPlaybackPause: () => void // Called when buffer is paused
, onPlaybackStopped: () => void // Called when buffer is stopped
, onPlaybackEnd: () => void // Called when the buffer ends
, onPlaybackSeek: (time: number) => void // Called after a seek
, onVolumeChange: (newLevel: number) => void // When the volume changes (not called on mute)
, getPlaybackTime: () => (time: number) // Current playback time
}

TODO:

  • Add more browser support.
  • Documentation.
0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.1.0

8 years ago