mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +00:00
Add BaseSoundManager#isPlaying
This commit is contained in:
parent
e337b6e4d1
commit
f01e2764c9
1 changed files with 46 additions and 0 deletions
|
@ -533,6 +533,52 @@ var BaseSoundManager = new Class({
|
|||
return stopped;
|
||||
},
|
||||
|
||||
/**
|
||||
* When a key is given, returns true if any sound with that key is playing.
|
||||
*
|
||||
* When no key is given, returns true if any sound is playing.
|
||||
*
|
||||
* @method Phaser.Sound.BaseSoundManager#isPlaying
|
||||
* @since 3.90.0
|
||||
*
|
||||
* @param {?string} key - Sound asset key.
|
||||
*
|
||||
* @return {boolean} - Per the key argument, true if any matching sound is playing, otherwise false.
|
||||
*/
|
||||
isPlaying: function (key)
|
||||
{
|
||||
var sounds = this.sounds;
|
||||
var i = sounds.length - 1;
|
||||
var sound;
|
||||
|
||||
if (key === undefined)
|
||||
{
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
sound = this.sounds[i];
|
||||
|
||||
if (sound.isPlaying)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
sound = this.sounds[i];
|
||||
|
||||
if (sound.key === key && sound.isPlaying)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method used internally for unlocking audio playback on devices that
|
||||
* require user interaction before any sound can be played on a web page.
|
||||
|
|
Loading…
Reference in a new issue