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

The soundjs will not work when the source url is a RESTFUL api. #284

Open Moxmi opened 6 years ago

Moxmi commented 6 years ago

as the follow:


      var src = 'http://dict.youdao.com/dictvoice?audio=testword';

      createjs.Sound.alternateExtensions = ["mp3"]; // add other extensions to try loading if the src file extension is not supported
      //createjs.Sound.onLoadComplete = playSound;  // add a callback for when load is completed
      createjs.Sound.addEventListener("fileload", function() {createjs.Sound.play('demo')}); // add an event listener for when load is completed
      createjs.Sound.registerSound(src, 'demo');  // register sound, which preloads by default```

This will raise the error that 'Type not recognized'.
sperrow commented 6 years ago

Have the same bug.

lannymcnie commented 5 years ago

This is because PreloadJS (which SoundJS under the hood) uses file extensions to automatically determine if a file source is a sound. You can hint to SoundJS/PreloadJS that a file is a sound using type.

createjs.Sound.registerSound({src: src, type:"sound"});

Further, if you have different MP3/OGG sources to support a wider browser list, you can pass an object with extensions a keys to indicated which sources are which file type, since no file extension is present to help out with that.

createjs.Sound.registerSound({src: {mp3: src1, ogg:src2}, type:"sound"});

It might make sense for SoundJS to be a little more permissive when adding string paths, since there is no need to determine the file type to try and load it as a sound. I will leave this open to track that feature.