/spela_json

SpelaJSON

Primary LanguageJavaScriptMIT LicenseMIT

SpelaJSON DevDependencies badge

SpelaJSON (swedish for PlayJSON), plays JSON using Web Audio API. I use it togheter with DiffSync, a implementation of Differential Syncronization in JavaScript, to let users edit the same audio file.

Installation

TODO

Example

let SpelaJSON = require('./index');

let file = {
  name: 'audiofile1',
  data: {
    '1': {
      type: 'file',
      file: '/alien_phaser.wav',
      start: 0
    },
    '2': {
      type: 'file',
      file: '/car.wav',
      start: 1.5
    },
    '3': {
      type: 'file',
      file: '/crumple_paper.wav',
      start: 3
    },
    '4': {
      type: 'file',
      file: '/mbira.wav',
      start: 5,
      rate: 4
    },
    '5': {
      type: 'file',
      file: '/surround.wav',
      start: 10,
      rate: 3
    }
  }
};

if (SpelaJSON.validate(file).length === 0) {
  var player = new SpelaJSON(file);
  player.play();
}

API

Player

Plays JSON. See example.

constructor(json, context)

Create a player-object with the JSON, and optional AudioContext. The browser only allow a few number of AudioContext.

Params:
  • Object json The audio json
  • AudioContext context

play()

Plays JSON, only if ready and all files is loaded.

Return:
  • Boolean true if the file can be played

stop()

Stops playing the file.

ready()

Check if JSON-file is ready, and all files are loaded.

Return:
  • Boolean true if all files are loaded

name()

Name of the JSON-file.

Return:
  • String name of the file

duration()

Duration of the whole JSON-file. Returns zero of file is not ready.

Return:
  • Number length of the file

setJSON(json)

Update JSON.

Params:
  • Object json The audio json

getJSON()

Get the JSON.

Return:
  • Object The audio json

Player.validate(json)

Validate the JSON.

Params:
  • Object json
Return:
  • Array errors

License

Copyright (c) 2015 Christian Nilsson

Licensed under the MIT license.