Core. SoundManager

SoundManager Is a sound management class. A playback control method for background music and sound effects is provided.

Constructor

new SoundManager()

Member

(static) autoStopMusic :Boolean

Do you stop the background music automatically after losing focus?.

(static) musicMuted :Boolean

(static) musicVolume :Number

Background music volume.
Default Value:
  • 1

(static) muted :Boolean

(static) playbackRate :Number

Sound playback speed.
Default Value:
  • 1

(static) soundMuted :Boolean

(static) soundVolume :Number

Sound volume.
Default Value:
  • 1

Methods

addChannel(channel)

Add a sound instance to play.
Parameters:
Name Type Description
channel SoundChannel SoundChannel Object.

destroySound(url)

Releasing sound resources.
Parameters:
Name Type Description
url String Sound playback address.

playMusic(url, loopsopt, completeopt, startTimeopt) → {SoundChannel}

Play background music. Background music can only play one at the same time. If you call this method again when playing background music, you will stop the previous background music and then broadcast the current background music.
Parameters:
Name Type Attributes Default Description
url String Sound file address.
loops int <optional>
0 loops The number of cycles, 0, represents infinite loops.
complete Handler <optional>
null complete Sound playback complete callback.
startTime Number <optional>
0 startTime Sound playback start time.
Returns:
Type:
SoundChannel
SoundChannel object, through which the object can control the sound and obtain the sound information.

playSound(url, loopsopt, completeopt, soundClassopt, startTimeopt) → {SoundChannel}

Play sound. The sound effects can be played simultaneously.
Parameters:
Name Type Attributes Default Description
url String Sound file address.
loops int <optional>
1 loops The number of cycles, 0, represents infinite loops.
complete Handler <optional>
null complete Sound playback completes callback Handler objects.
soundClass Class <optional>
null soundClass Use which sound class to play, and null indicates automatic selection.
startTime Number <optional>
0 startTime Sound playback start time.
Returns:
Type:
SoundChannel
SoundChannel object, through which the object can control the sound and obtain the sound information.

removeChannel(channel)

Removes the sound instance that is played.
Parameters:
Name Type Description
channel SoundChannel SoundChannel Object.

setMusicVolume(volume)

Set background music volume. Volume range from 0 (mute) to 1 (maximum volume).
Parameters:
Name Type Description
volume Number Volume. The initial value is 1. Volume range from 0 (mute) to 1 (maximum volume).

setSoundVolume(volume, urlopt)

Set sound volume. Depending on the parameters, you can set the volume of the specified sound (background music or sound effects), volume, or all sound effects (not including background music).
Parameters:
Name Type Attributes Default Description
volume Number Volume. The initial value is 1. Volume range from 0 (mute) to 1 (maximum volume).
url String <optional>
null url (default = null) sound playback address. The default is null. Represents the volume of all sound effects (not including background music) for empty, and does not indicate the setting of the volume of the specified sound (background music or sound effects).

stopAll()

Stop playing all sounds (including background music and sound effects).

stopAllSound()

Stop playing all sound effects (not including background music).

stopMusic(url)

Stop playing background music (not including sound effects).
Parameters:
Name Type Description
url Sound file address.

stopSound(url)

Stop playing sound. This method can stop any sound playback (including background music and sound effects), only by entering the corresponding sound playback address.
Parameters:
Name Type Description
url String Sound file address.