kleepklep Posted February 20, 2015 Share Posted February 20, 2015 I have a project where I have parts of a song broken into separate audio files that I need to play in a random sequence without a gap in the audio. I verified that the sounds are seamless by looping them in both audio editing programs and in Phaser after learning to use m4a files instead of mp3 files. Unfortunately, there is a gap between the audio files that I can't figure out how to get rid of. Here is the code that I am using. Anyone have any ideas about how to solve this problem? Any help would be much appreciated. Thanks! function songTest() { var song = game.add.audio(game.rnd.pick(['song1', 'song2', 'song3'])); song.play(); song.onStop.add(songTest, game);} Link to comment Share on other sites More sharing options...
mxmlb Posted February 20, 2015 Share Posted February 20, 2015 Hi, Is it a big or a small gap ? Maybe game.add.audio is taking a little time to create the Sound object.If you don't have a tremendous amount of different sounds, you can do all the game.add.audio() in the initialization of your game, and just pick a random one at runtime.Pseudo-code : in the create function : this.mySounds = [];this.mySounds.push(game.add.audio('song1');this.mySounds.push(game.add.audio('song2');this.mySounds.push(game.add.audio('song3'); in songTest : var song = this.mySounds[Math.random() * this.mySounds.length << 0];song.onStop.addOnce(songTest, game);song.play(); On another note, you could also create an audiosprite, si you have only one sound loaded. Link to comment Share on other sites More sharing options...
kleepklep Posted February 20, 2015 Author Share Posted February 20, 2015 It is a very short gap. I actually thought about that too and previously tried creating the sounds ahead of time and again now just to make sure, but there's still a gap. I did not know about AudioSprite. Reviewing the docs at http://docs.phaser.io/Phaser.AudioSprite.html, I do not see a method to either detect an individual sound's position or when it completes, so I'm not sure how that would work for me. Link to comment Share on other sites More sharing options...
ptdnet Posted February 20, 2015 Share Posted February 20, 2015 I haven't played with the sound at all yet, but I'm willing to predict that once a sound ends and fires off the message that it's done, nothing happens until the next loop update when Phaser says "hey we better answer that callback." Link to comment Share on other sites More sharing options...
jouniii Posted March 5, 2015 Share Posted March 5, 2015 Webaudio would allow queueing into future, but Phaser Sound only fires the play when called. Thus is causes small gaps. To have seamless playback you need a bit latency and tell in advance the webaudio to play next sound. This is how real sequencers work anyhow. Link to comment Share on other sites More sharing options...
Matthew Cooley Posted March 5, 2015 Share Posted March 5, 2015 Phaser's Sound class has a currentTime property that you could monitor, as well as a totalDuration property. Link to comment Share on other sites More sharing options...
Recommended Posts