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 play failed when the source url is a RESTFUL api #306

Open void-soul opened 5 years ago

void-soul commented 5 years ago

Issue Details

Latest SoundJS 1.0.2 https://cdnjs.cloudflare.com/ajax/libs/SoundJS/1.0.2/soundjs.min.js

Whats happening:

When playing a sound from a RESTFUL api, the instanse's playstate is null (sometimes it's failed)

Demo here: https://codepen.io/d925529/pen/gjomKd

lannymcnie commented 5 years ago

This is mostly likely caused by the file path for your sound containing a query string (specifically "?"). This isn't incorrect, but PreloadJS/SoundJS doesn't accept it as a valid file path.

Info for solving this: The PATH_PATTERN for PreloadJS is

/^(?:(\w+:)\/{2}(\w+(?:\.\w+)*\/?))?([\/.]*?(?:[^?]+)?\/)?((?:[^\/?]+)\.(\w+))(?:\?(\S+)?)?$/

Specifically, the _parsePath method returns false when it encounters this path.

https://upload.emeker.com/?key=9398bd6f43b350cf72cf2e6155e31cb5e1cbf2ba.mp3&token=8fd185e927258830f9ed828d1bada179c8aeaeed159ccc1c906cc20667a44728d0afe7b579c49975911c3bb6ad06aace:3c9b6ad38729e04071de1377d5214589&name=bgm.mp3

A saved RegExr pattern is here: https://regexr.com/3t6d0 [Updated Link: https://regexr.com/343kr]

Just accepting the query string may cause issues with other parts of PreloadJS/SoundJS, so it will need to be tested thoroughly.

tjutasi commented 4 years ago

I run into a similar problem, but the regexr link above takes me to the default page on regexr. Does happened something with this since 2018 ?

lannymcnie commented 4 years ago

Nothing has changed in the library (see discussion here)

The RegExr pattern can be found here: https://regexr.com/343kr - not sure why the old one no longer works.

tjutasi commented 4 years ago

Thank you, that regex patter doesn't work for me either, but removing the ? exclusion from the original pattern did the job. Will we see something about this consortium on createjs.com ? or here ? the slack link is not valid anymore.