phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Phaser.Loader. Errors in getAudioURL() and getVideoURL() using BLOB: or DATA:

Open jackfreak opened this issue 11 years ago • 5 comments

I'm trying to load sounds using data-uri scheme and I've found a small bug when using {uri: .., type: ..} pair.

In the preload() function of a state I add my audio like this:

game.load.audio('Music', [{uri: 'data:audio/mp3;base64,SUQzAwAAAAAAFgAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/+3BAAAAB/Rg.....', type: 'mp3'}] );

But when the audio gets loaded I get the error: Phaser.Loader - audio[Music]: error loading asset from URL false (No supported audio URL specified or device does not have audio playback support)

I've tracked the error and is easily fixable, the problem is inside the getAudioURL() method of the Loader manager: When using url-type pairs, the url property gets overwritten before we can set the audioType property.

Currently the code looks like this:

            var url = urls[i];
            var audioType;

            if (url.uri) // {uri: .., type: ..} pair
            {
                url = url.uri;
                audioType = url.type;
            }
            else

And should be like this:

            var url = urls[i];
            var audioType;

            if (url.uri) // {uri: .., type: ..} pair
            {
                audioType = url.type;
                url = url.uri;
            }
            else

Also at the end of the for-loop, if we defined the audio with a {uri: .., type: ..} pair the code returns the url object that's inside the urls array instead of the url with the 'data:'

         if (this.game.device.canPlayAudio(audioType))
            {
                return urls[i];
            }

... so it breaks in the xhrLoad line of the loadFile() method when this.transfromUrl() gets executed because file.url is an Object instead of an url:

this.xhrLoad(file, this.transformUrl(file.url, file), 'arraybuffer', this.fileComplete);

To fix this, getAudioURL() should be like:

         if (this.game.device.canPlayAudio(audioType))
            {
                return url;
            }

We'll find these bugs in getVideoURL() too.

jackfreak avatar Nov 29 '15 23:11 jackfreak

I made a PR (#2236) to fix this, just making your changes in the Phaser.Loader source.

twilligon avatar Nov 30 '15 22:11 twilligon

Excellent, thanks!, I'm still new to all things related to git.

jackfreak avatar Nov 30 '15 22:11 jackfreak

Thanks both, fixed via PR merge.

photonstorm avatar Feb 01 '16 16:02 photonstorm

I user v2.5 but I same error Phaser.Loader - audio[s-start]: error loading asset from URL false (No supported audio URL specified or device does not have audio playback support)

lilijreey avatar Jul 13 '16 15:07 lilijreey

@lilijreey if you want this looked at, it needs opening as a new issue, with a demonstrable test case. Comments to old / dead threads don't ever progress beyond that I'm afraid.

photonstorm avatar Jul 13 '16 15:07 photonstorm