Jump to content

Decoding a simple 300kb audiosprite takes forever on PC. Still waiting after 5 mins.


kriket
 Share

Recommended Posts

if (this.cache.isSoundDecoded('sound')){            console.log('tom');            this.state.start('OpeningScene');}
 
This code never runs. Been waiting forever. No errors in console. If I comment out the if statement, then console logs and OpeningScene state loads. 
 
 
 

Preloading code.

    //AudioSprites    if (this.game.device.firefox || this.game.device.chrome || this.game.device.chromeOS) {        this.game.load.audiosprite('sound', 'assets/audio/output.ogg', 'assets/audio/output.json');    } else {        this.game.load.audiosprite("sound", 'assets/audio/output.m4a', 'assets/audio/output.json');     }

 

 

Audiosprites are 207kb and 138kb respectively, and only 17 seconds long. 

 

BTW, tried on chrome, firefox on windows and chromium and firefox on ubuntu, to no avail. 

Link to comment
Share on other sites

You can load your sounds like this:

this.load.audio("SFX", ["assets/sfx.ogg", "assets/sfx.m4a"]);

Phaser will take care whether to load .ogg or .m4a.

 

Be sure, that your code for checking is in update() method (not preload, nor create) as you need to check every frame (I use this approach and it works ... taken from Phaser project templete (at Phaser\resources\Project Templates\Full Screen Mobile\src\Preloader.js):

        update() {            // run only once - once the music is decoded do state switch            if (this.cache.isSoundDecoded("SFX") && this._ready === false) {                this._ready = true;                this.game.state.start("Menu");            }        }
Link to comment
Share on other sites

 

You can load your sounds like this:

this.load.audio("SFX", ["assets/sfx.ogg", "assets/sfx.m4a"]);

Phaser will take care whether to load .ogg or .m4a.

 

Be sure, that your code for checking is in update() method (not preload, nor create) as you need to check every frame (I use this approach and it works ... taken from Phaser project templete (at Phaser\resources\Project Templates\Full Screen Mobile\src\Preloader.js):

        update() {            // run only once - once the music is decoded do state switch            if (this.cache.isSoundDecoded("SFX") && this._ready === false) {                this._ready = true;                this.game.state.start("Menu");            }        }

 

But I wanted to use the audiosprite for performance sake as I am targetting mobiles. Also there are about 10 one second sounds and audiosprites really are the way to go for me. 

 

PS - Do appreciate the tip about using update in preload.js. I was using create() and it did work (at least without that if statement) but its the wrong way to do this. 

Link to comment
Share on other sites

1)

But I wanted to use the audiosprite for performance sake as I am targetting mobiles

 

 

it is the same for audiosprites - you can put array of urls and the best one will be choosen:

audiosprite: function(key, urls, jsonURL, jsonData, autoDecode)

2) even if you load audio with this.load.audio you can still use it as audiosprite - but you have to add markers. I am doing it this way as for old IE I noticed, that beginning of sound is cut. So I shifted start of all sounds to begin earlier if on IE (in the end of silence gap for previous sound):

            var soundshift: number = 0;            if (this.game.device.ie && this.game.device.ieVersion <= 10) {                soundshift = 0.02;            }            sfx.addMarker("bomb", 0.0000, 0.4278);            sfx.addMarker("branch", 1.9000 - soundshift, 0.6226 + soundshift);            sfx.addMarker("click", 4.0000 - soundshift, 0.5 + soundshift);

3) I am using "ready" variable as it were in template. I think it is only "safety" check to prevent change of state to be called more than once. This probably will not happen... This variable is internal variable for current state (not any "system" or other library variable) - you can call it as you wish.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...