MarkPal 3 Report post Posted April 20, 2015 Hello all,I've nearly finished one big game using Phaser and today I encountered a problem I haven't noticed before: all the audio files I have set to loop doesn't loop in Chrome browser. This happens with both desktop and mobile. When I play my game using Opera or Firefox all these audio files play flawlessly and loop. I'm using ogg and m4a as file formats for music files. For sfx I'm using wav, ogg and m4a. Have you got any ideas what could be the cause of this problem?I'm using Phaser 2.1.2 and for looping sounds I'm doing this:this.levelMusic.play('', 0, 1, true);In Chrome, despite the boolean value for loop being true, the audio file plays only once. If I check from console the value of looping (this.levelMusic.loop) it also says it's true. All help is much appreciated. - Marko Quote Share this post Link to post Share on other sites
Henryk 3 Report post Posted April 20, 2015 I experienced a simular issues. Though I'm using Phaser 2.2.0.After taking it out my fadein event the sound looped. No idea why. I use now: sndGame.loop = true; sndGame.play(); //sndGame.fadeIn(2000); 1 asc3ndpony reacted to this Quote Share this post Link to post Share on other sites
limion 0 Report post Posted April 20, 2015 Yes, the same problem.I had to make somethink like that:update: function(){ if(!this.mysound.isPlaying){ this.mysound.play('',0,volume); } } Quote Share this post Link to post Share on other sites
rich 2610 Report post Posted April 21, 2015 Someone upload a minimal test case please, because this one works fine for me in Chrome and Canary: http://phaser.io/examples/v2/audio/loop Quote Share this post Link to post Share on other sites
DDowell 0 Report post Posted April 21, 2015 Seems like the issue is not with loopFull but with the loop flag on play. Quote Share this post Link to post Share on other sites
rich 2610 Report post Posted April 21, 2015 All loopFull does though is this: loopFull: function (volume) { this.play(null, 0, volume, true); }, Quote Share this post Link to post Share on other sites
DDowell 0 Report post Posted April 21, 2015 var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });function preload() { game.load.image('speakers','assets/sprites/speakers.png'); game.load.audio('bass', 'assets/audio/tech/bass.mp3'); game.load.audio('drums', 'assets/audio/tech/drums.mp3'); game.load.audio('percussion', 'assets/audio/tech/percussion.mp3'); game.load.audio('synth1', 'assets/audio/tech/synth1.mp3'); game.load.audio('synth2', 'assets/audio/tech/synth2.mp3'); game.load.audio('top1', 'assets/audio/tech/top1.mp3'); game.load.audio('top2', 'assets/audio/tech/top2.mp3');}var bass;var drums;var percussion;var synth1;var synth2;var top1;var top2;var text;var sounds;var current;var speakers;var loopCount = 0;function create() { game.stage.backgroundColor = '#838282'; speakers = game.add.image(game.world.centerX, 500, 'speakers'); speakers.anchor.set(0.5, 1); var style = { font: "65px Arial", fill: "#52bace", align: "center" }; text = game.add.text(game.world.centerX, 100, "decoding", style); text.anchor.set(0.5); bass = game.add.audio('bass'); drums = game.add.audio('drums'); percussion = game.add.audio('percussion'); synth1 = game.add.audio('synth1'); synth2 = game.add.audio('synth2'); top1 = game.add.audio('top1'); top2 = game.add.audio('top2'); console.log("bass!" + bass); bass.onDecoded.addOnce(start, this); sounds = [ bass, drums, percussion, synth1, synth2, top1, top2 ]; // Being mp3 files these take time to decode, so we can't play them instantly // Using setDecodedCallback we can be notified when they're ALL ready for use. // The audio files could decode in ANY order, we can never be sure which it'll be. //game.sound.setDecodedCallback(sounds, start, this); start();}function start() { bass.play("",0,1,true,true); bass.onLoop.add(hasLooped, this); text.text = 'bass';}function hasLooped(sound) { console.log("bass looped!");}This example (played through the sandbox) works in 2.3.0 but fails in previous version (2.2.2 and earlier). This is in Chrome only. Quote Share this post Link to post Share on other sites
rich 2610 Report post Posted April 21, 2015 Yes there was a web audio looping specific bug fixed in 2.3 (where the loop property was set, but ignored because it still specified an offset position, Chrome changed and this no longer works for looping, so now you just set loop to true and DON'T give any offset like we do in 2.3 and all is fine again). From the 2.3 change log:Sound in Web Audio now uses AudioContext.onended to trigger when it will stop playing instead of using a time based value. This is only used if the sound doesn't loop and isn't an audio sprite, but will give a much more accurate `Sound.onStop` event. It also prevents short audio files from being cut off during playback (#1471) and accounts for time spent decoding.andSound.loop even when set for WebAudio wouldn't use the AudioContext loop property because Sound.start was being invoked with an offset and duration. Now if `loop` is true and no marker is being used it will use the native Web Audio loop support (#1431) Quote Share this post Link to post Share on other sites
DDowell 0 Report post Posted April 21, 2015 Yes there was a web audio looping specific bug fixed in 2.3 (where the loop property was set, but ignored because it still specified an offset position, Chrome changed and this no longer works for looping, so now you just set loop to true and DON'T give any offset like we do in 2.3 and all is fine again). Sorry for being thick but if you want to play a looping sound AND have a starting position other than 0, is that possible? Is it possible only in 2.3? Quote Share this post Link to post Share on other sites
rich 2610 Report post Posted April 21, 2015 Yes it's possible but it can't use the WebAudio loop property to do it, it has to do it using a millisecond timer - which isn't always that accurate, especially for short sounds or sounds that require perfect looping. Quote Share this post Link to post Share on other sites
phantomas 3 Report post Posted April 21, 2015 If you are using a Phaser version below 2.3 this is the solution that worked for me: this.theme_aud.onStop.addOnce(function() { this.theme_aud.play(); }, this); Quote Share this post Link to post Share on other sites
jos3k4 0 Report post Posted April 26, 2015 Is not clear for me if this is solved for MarkPal...but what I'm using now is the following code to make a loop (Working in chrome)//Start the soundtrack!soundtrack = game.add.audio('bso');soundtrack.loop = true;soundtrack.play(); Quote Share this post Link to post Share on other sites
MarkPal 3 Report post Posted April 27, 2015 Thank you all for your tips and clarifications. I got it to work by doing this: this.levelMusic.play('', 0, 1, true);this.levelMusic.onLoop.add(this.playLevelMusic, this);And then with the function playLevelMusic I set it to play once again: playLevelMusic: function() { this.levelMusic.play('', 0, 1, true);}That way it seems to work for me. Somewhat similar to phantomas' solution. Dunno if this is very efficient, though. Quote Share this post Link to post Share on other sites
stupot 46 Report post Posted April 30, 2015 I'm experiencing this problem too, though am not using Phaser's sound. Looks like it's down to a recent Chrome update and not being fixed until 43, more info here: https://code.google.com/p/chromium/issues/detail?id=457099 1 MichaelD reacted to this Quote Share this post Link to post Share on other sites