phaserjs / phaser-ce

Phaser CE is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
http://phaser.io
MIT License
1.34k stars 491 forks source link

Strange audio bug only on Window 10 Phone (Edge) #635

Closed SBCGames closed 5 years ago

SBCGames commented 5 years ago

Hi, I found really very strange bug. It happens only on my Windows 10 Phone (Lumia 532) in Edge browser. When my game tries to play music, browser hangs. It is not easy to debug on this device, so I used Vorlonjs and here is image with log output:

SoundBug

There are no details on error. So, i tracked it down to core and also tried several Phser versions. Bug starts from Phaser 2.10.6. Version 2.10.5 is last version, that works without error.

I found, that problematic line of code is this one: https://github.com/photonstorm/phaser-ce/blob/master/src/sound/Sound.js#L721

this._startSource(0, 0);

And it is where strange things start to happen. On screenshot, line before error is debug output from _startSource method. It is OK to start source with undefined duration, but for some reason WP10+Lumia does not like this. If I pass duration into method like bellow, everything works:

this._startSource(0, 0, this.totalDuration);

So, I thought, that for some reason, it doesn't like undefined duration. But older Phaser versions were doing this and no error was thrown. I changed that line to this:

this._sound.start(0, 0);

which is exactly the same as it is now inside _startSource and it works!

I ended with this workaround:

this._sound.start(when || 0, offset || 0, duration || this.totalDuration);

In the end: error happens only when duration is undefined and this._sound.start is called from inside _startSource(). If duration is defined or this._sound.start is called directly in play() method, everything works. As pointed earlier, this is specific bug to WP10 + Edge (+ Lumia 532 ... not tested on other WP10 phones). Windows Edge works without problem.

Not sure, whether you will do something with this. At least it is documented here if anyone else encounters it.

samme commented 5 years ago

Do you think I should modify Phaser.Sound#_startSource like this?

this._sound.start(when || 0, offset || 0, duration || this.totalDuration);
SBCGames commented 5 years ago

@samme Hi, this was my original workaround. But it looks, it plays whole audio only once. Now, I am using this workaround:

  this._sound.start(when || 0, offset || 0, duration || (this.totalDuration * 999));

It works for me, because I use long individual clips for music and audio sprites for SFX. Audio sprites have duration defined. What has no duration defined is music and I play it always in loops. So, it would be better to take loop into account - something like this:

  this._sound.start(when || 0, offset || 0, duration || (this.totalDuration * (this.loop ? 999 : 1)));