mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 07:04:31 +00:00
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.
This commit is contained in:
parent
eba1743404
commit
ef3cb1f31d
2 changed files with 30 additions and 2 deletions
|
@ -148,6 +148,7 @@ We've also removed functions and properties from Pixi classes that Phaser doesn'
|
|||
* PIXI.TextureSilentFail is a boolean that defaults to `false`. If `true` then `PIXI.Texture.setFrame` will no longer throw an error if the texture dimensions are incorrect. Instead `Texture.valid` will be set to `false` (#1556)
|
||||
* InputHandler.enableDrag with a boundsRect set now takes into account the Sprites anchor when limiting the drag (thanks @unindented #1593)
|
||||
* InputHandler.enableDrag with a boundsSprite set now takes into account both the Sprites anchor and the boundsSprite anchor when limiting the drag.
|
||||
* 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.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
|
|
@ -376,6 +376,20 @@ Phaser.Sound.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called automatically by the AudioContext when the sound stops playing.
|
||||
* Doesn't get called if the sound is set to loop or is a section of an Audio Sprite.
|
||||
*
|
||||
* @method Phaser.Sound#onEndedHandler
|
||||
* @protected
|
||||
*/
|
||||
onEndedHandler: function () {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.stop();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called automatically by Phaser.SoundManager.
|
||||
* @method Phaser.Sound#update
|
||||
|
@ -423,7 +437,11 @@ Phaser.Sound.prototype = {
|
|||
}
|
||||
else
|
||||
{
|
||||
this.stop();
|
||||
// Stop if we're using an audio marker, otherwise we let onended handle it
|
||||
if (this.currentMarker !== '')
|
||||
{
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -595,13 +613,20 @@ Phaser.Sound.prototype = {
|
|||
this._sound.loop = true;
|
||||
}
|
||||
|
||||
if (!this.loop && marker === '')
|
||||
{
|
||||
this._sound.onended = this.onEndedHandler.bind(this);
|
||||
}
|
||||
|
||||
this.totalDuration = this._sound.buffer.duration;
|
||||
|
||||
// console.log('dur', this._sound.buffer.duration, Math.ceil(this._sound.buffer.duration * 1000));
|
||||
|
||||
if (this.duration === 0)
|
||||
{
|
||||
// console.log('duration reset');
|
||||
this.duration = this.totalDuration;
|
||||
this.durationMS = this.totalDuration * 1000;
|
||||
this.durationMS = Math.ceil(this.totalDuration * 1000);
|
||||
}
|
||||
|
||||
// Useful to cache this somewhere perhaps?
|
||||
|
@ -788,6 +813,8 @@ Phaser.Sound.prototype = {
|
|||
*/
|
||||
stop: function () {
|
||||
|
||||
if (typeof fromNative === 'undefined') { fromNative = false; }
|
||||
|
||||
if (this.isPlaying && this._sound)
|
||||
{
|
||||
if (this.usingWebAudio)
|
||||
|
|
Loading…
Reference in a new issue