CreateJS / SoundJS

A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.
http://createjs.com/
MIT License
4.42k stars 838 forks source link

Re-registration of an audio file #278

Closed vladimirmyshkovski closed 6 years ago

vladimirmyshkovski commented 6 years ago

Hey. I need to re-register the same file (it is overwritten on the backend) by the event. How can i do this?

If I try to register it, as described in the documentation, it is registered only once.

createjs.Sound.on("fileload", this.loadHandler, this); // register file

function loadHandler(event) {
    createjs.Sound.play("x"); // play sound handler
}

socket.onmessage = function(e) {
    createjs.Sound.registerSound("resources/text.wav", "x"); // again register file
    loadHandler() // call handler 
}

Thanks

vladimirmyshkovski commented 6 years ago

This is solve of the my issue:

function initialHandler(event) {
  Voice = "resources/" + data.filename + ".wav";
  playHandler();
}
function registerHandler() {
  createjs.Sound.registerSound(Voice);
  createjs.Sound.on("fileload", playHandler);
}
function playHandler() {
  if(createjs.Sound.loadComplete(Voice)) {
    createjs.Sound.play(Voice);
  } else {
    registerHandler()
  }
}