Class AudioPlayer
Base class for audio players
Namespace: Doozy.Runtime.Soundy
Assembly: cs.temp.dll.dll
Syntax
public abstract class AudioPlayer : MonoBehaviour
Fields
Clip
Audio clip that is currently loaded in this audio player
Declaration
protected AudioClip Clip
Field Value
Type | Description |
---|---|
AudioClip |
CrossFade
Enable or disable cross fading when starting or stopping a sound
Declaration
protected bool CrossFade
Field Value
Type | Description |
---|---|
Boolean |
CrossFadeDuration
If cross fade is enabled, this is the duration (in seconds) of the fade in and out of the audio player's volume when starting or stopping a sound
Declaration
protected float CrossFadeDuration
Field Value
Type | Description |
---|---|
Single |
DopplerLevel
Doppler scale for this audio player
Declaration
protected float DopplerLevel
Field Value
Type | Description |
---|---|
Single |
FollowTransform
Target transform to follow (usually a Transform that is attached to a GameObject that is moving) while playing
Declaration
protected Transform FollowTransform
Field Value
Type | Description |
---|---|
Transform |
IgnoreListenerPause
Allow this audio player to play even though AudioListener.pause is set to true. This is useful for the menu element sounds or background music in pause menus.
Declaration
protected bool IgnoreListenerPause
Field Value
Type | Description |
---|---|
Boolean |
Loop
Check if the audio player is looping the currently playing audio clip
Declaration
protected bool Loop
Field Value
Type | Description |
---|---|
Boolean |
MaxDistance
(Logarithmic rolloff) Set the distance a sounds stops attenuating at
Declaration
protected float MaxDistance
Field Value
Type | Description |
---|---|
Single |
MinDistance
Set the minimum distance within the audio source will cease to grow louder in volume
Declaration
protected float MinDistance
Field Value
Type | Description |
---|---|
Single |
OutputAudioMixerGroup
Audio mixer group to route the signal to.
Declaration
protected AudioMixerGroup OutputAudioMixerGroup
Field Value
Type | Description |
---|---|
AudioMixerGroup |
PanStereo
Set the pan level (left / right bias) of the audio. This only applies to sounds that are Mono or Stereo.
Declaration
protected float PanStereo
Field Value
Type | Description |
---|---|
Single |
Pitch
Pitch of the audio player.
Declaration
protected float Pitch
Field Value
Type | Description |
---|---|
Single |
Priority
Audio player's priority
Declaration
protected int Priority
Field Value
Type | Description |
---|---|
Int32 |
RecycleAfterUse
Declaration
protected bool RecycleAfterUse
Field Value
Type | Description |
---|---|
Boolean |
ReverbZoneMix
The amount by which the signal from this sound will be mixed into the global reverb associated with the Reverb Zones.
Declaration
protected float ReverbZoneMix
Field Value
Type | Description |
---|---|
Single |
SpatialBlend
Set how much this audio player is affected by 3D spatialisation calculations (attenuation, doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3.
Declaration
protected float SpatialBlend
Field Value
Type | Description |
---|---|
Single |
Spread
Set the spread angle (in degrees) of a 3d stereo or multichannel sound in speaker space
Declaration
protected float Spread
Field Value
Type | Description |
---|---|
Single |
Volume
Volume of the audio player
Declaration
protected float Volume
Field Value
Type | Description |
---|---|
Single |
Properties
adjustedCrossFadeDuration
In case the cross fade duration is longer than the clip length, we want to make sure the cross fade duration is not longer than half the clip length. This is the real fade duration used to fade in and out the audio player's volume.
Declaration
protected float adjustedCrossFadeDuration { get; }
Property Value
Type | Description |
---|---|
Single |
autoFadeInStarted
Internal flag to keep track if the automated fade in process has started or not.
Declaration
public bool autoFadeInStarted { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean |
autoFadeOutStarted
Internal flag to keep track if the automated fade out process has started or not.
Declaration
public bool autoFadeOutStarted { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean |
autoPaused
Internal variable used to detect when Unity pauses this player's AudioSource (this happens on app focus lost, for example)
Declaration
protected virtual bool autoPaused { get; }
Property Value
Type | Description |
---|---|
Boolean |
canBeRecycled
Check if this audio player can be recycled. This means that the player is idle and it has been idle for more than the idle time. Also, the player must be set to recycle after use (RecycleAfterUse = true)
Declaration
public bool canBeRecycled { get; }
Property Value
Type | Description |
---|---|
Boolean |
clip
Audio clip that is currently loaded in this audio player
Declaration
public virtual AudioClip clip { get; set; }
Property Value
Type | Description |
---|---|
AudioClip |
clipLength
Duration (in seconds) of the audio clip that is currently playing
Declaration
public float clipLength { get; }
Property Value
Type | Description |
---|---|
Single |
crossFade
Should the audio player fade in and out when starting or stopping a sound
Declaration
public virtual bool crossFade { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
crossFadeDuration
Fade in and out duration (in seconds) of the audio player's volume when starting or stopping a sound
Declaration
public virtual float crossFadeDuration { get; set; }
Property Value
Type | Description |
---|---|
Single |
dopplerLevel
Doppler scale for this audio player
Declaration
public virtual float dopplerLevel { get; set; }
Property Value
Type | Description |
---|---|
Single |
fadeInCoroutine
Coroutine that fades in the audio player
Declaration
protected Coroutine fadeInCoroutine { get; set; }
Property Value
Type | Description |
---|---|
Coroutine |
fadeOutCoroutine
Coroutine that fades out the audio player
Declaration
protected Coroutine fadeOutCoroutine { get; set; }
Property Value
Type | Description |
---|---|
Coroutine |
followTarget
Target transform to follow (usually a Transform that is attached to a GameObject that is moving) while playing
Declaration
public virtual Transform followTarget { get; set; }
Property Value
Type | Description |
---|---|
Transform |
frameCountInRed
Declaration
protected string frameCountInRed { get; }
Property Value
Type | Description |
---|---|
String |
hasClip
Check if this audio player has an audio clip loaded
Declaration
public bool hasClip { get; }
Property Value
Type | Description |
---|---|
Boolean |
hasCrossFade
Check if the audio player has cross fade enabled and a cross fade duration greater than 0.
Declaration
public bool hasCrossFade { get; }
Property Value
Type | Description |
---|---|
Boolean |
idleDuration
Duration (in seconds) since this audio player last played an audio clip. This is used to mark the player as idle
Declaration
public virtual float idleDuration { get; }
Property Value
Type | Description |
---|---|
Single |
ignoreListenerPause
Allow this audio player to play even though AudioListener.pause is set to true. This is useful for the menu element sounds or background music in pause menus.
Declaration
public virtual bool ignoreListenerPause { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
inPool
Check if this audio player is currently in the pool (not in use)
Declaration
public bool inPool { get; }
Property Value
Type | Description |
---|---|
Boolean |
inUse
Check if this audio player is currently in use (out of the pool)
Declaration
public bool inUse { get; }
Property Value
Type | Description |
---|---|
Boolean |
isFading
Check if this audio player is currently fading in or out
Declaration
public bool isFading { get; }
Property Value
Type | Description |
---|---|
Boolean |
isFadingIn
Check if this audio player is currently fading in. This means that the audio player started playing an audio clip and is fading the volume in.
Declaration
public bool isFadingIn { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean |
isFadingOut
Check if this audio player is currently fading out. This means that the audio player is fading the volume out and will stop playing the audio clip when the volume reaches 0.
Declaration
public bool isFadingOut { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean |
isFollowingTarget
Check if this audio player is currently following a target
Declaration
public bool isFollowingTarget { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean |
isIdle
Check if this audio player is currently idle (it is not playing or paused and it has been idle for more than the idle time)
Declaration
public bool isIdle { get; }
Property Value
Type | Description |
---|---|
Boolean |
isLooping
Check if this audio player is currently looping the audio clip that is playing
Declaration
public bool isLooping { get; }
Property Value
Type | Description |
---|---|
Boolean |
isMuted
Check if this audio player is currently muted
Declaration
public bool isMuted { get; }
Property Value
Type | Description |
---|---|
Boolean |
isPaused
Check if this audio player is currently paused (it is playing but the AudioSource is paused)
Declaration
public bool isPaused { get; }
Property Value
Type | Description |
---|---|
Boolean |
isPlaying
Check if this audio player is currently playing an audio clip
Declaration
public bool isPlaying { get; }
Property Value
Type | Description |
---|---|
Boolean |
isPlayingMusic
Check if this audio player is currently playing a music object
Declaration
public bool isPlayingMusic { get; }
Property Value
Type | Description |
---|---|
Boolean |
isPlayingSound
Check if this audio player is currently playing a sound object
Declaration
public bool isPlayingSound { get; }
Property Value
Type | Description |
---|---|
Boolean |
isStopped
Check if this audio player is currently stopped (it is not playing and the AudioSource is not paused)
Declaration
public bool isStopped { get; }
Property Value
Type | Description |
---|---|
Boolean |
lastPlayedTime
Last time this audio player played an audio clip (in seconds). This is used to detect when the player is idle
Declaration
public virtual float lastPlayedTime { get; protected set; }
Property Value
Type | Description |
---|---|
Single |
loadedMusicObject
The MusicObject that is currently loaded in this audio player. When a MusicObject is loaded, the loaded SoundObject is set to null.
Declaration
public MusicObject loadedMusicObject { get; set; }
Property Value
Type | Description |
---|---|
MusicObject |
loadedSoundObject
The SoundObject that is currently loaded in this audio player. When a SoundObject is loaded, the loaded MusicObject is set to null.
Declaration
public SoundObject loadedSoundObject { get; set; }
Property Value
Type | Description |
---|---|
SoundObject |
loop
Check if the audio player is looping the currently playing audio clip
Declaration
public bool loop { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
maxDistance
(Logarithmic rolloff) Set the distance a sounds stops attenuating at
Declaration
public virtual float maxDistance { get; set; }
Property Value
Type | Description |
---|---|
Single |
minDistance
Set the minimum distance within the audio source will cease to grow louder in volume
Declaration
public virtual float minDistance { get; set; }
Property Value
Type | Description |
---|---|
Single |
mute
Check if this audio player is currently muted
Declaration
public virtual bool mute { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
onDispose
Callback executed when the audio player is disposed
Declaration
public UnityAction onDispose { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onFadeInFinish
Callback executed when the audio player finishes fading in
Declaration
public UnityAction onFadeInFinish { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onFadeInStart
Callback executed when the audio player starts fading in
Declaration
public UnityAction onFadeInStart { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onFadeOutFinish
Callback executed when the audio player finishes fading out
Declaration
public UnityAction onFadeOutFinish { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onFadeOutStart
Callback executed when the audio player starts fading out
Declaration
public UnityAction onFadeOutStart { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onFinish
Callback executed when the audio player finishes playing
Declaration
public UnityAction onFinish { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onPause
Callback executed when the audio player pauses
Declaration
public UnityAction onPause { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onPlay
Callback executed when the audio player starts playing
Declaration
public UnityAction onPlay { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onRecycle
Callback executed when the audio player is recycled
Declaration
public UnityAction onRecycle { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onResume
Callback executed when the audio player resumes
Declaration
public UnityAction onResume { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onStop
Callback executed when the audio player stops playing
Declaration
public UnityAction onStop { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
onUpdate
Callback executed every frame while the audio player is playing
Declaration
public UnityAction onUpdate { get; set; }
Property Value
Type | Description |
---|---|
UnityAction |
outputAudioMixerGroup
Audio mixer to route the signal to
Declaration
public virtual AudioMixerGroup outputAudioMixerGroup { get; set; }
Property Value
Type | Description |
---|---|
AudioMixerGroup |
panStereo
Set the pan level (left / right bias) of the audio. This only applies to sounds that are Mono or Stereo.
Declaration
public virtual float panStereo { get; set; }
Property Value
Type | Description |
---|---|
Single |
pitch
Pitch of the audio player
Declaration
public virtual float pitch { get; set; }
Property Value
Type | Description |
---|---|
Single |
playProgress
Play progress (from 0 to 1) of the audio clip that is currently playing
Declaration
public virtual float playProgress { get; protected set; }
Property Value
Type | Description |
---|---|
Single |
playState
Current play state of this audio player
Declaration
public PlayState playState { get; protected set; }
Property Value
Type | Description |
---|---|
PlayState |
priority
Set the priority of the audio. Unity virtualizes AudioSources when there are more AudioSources playing than available hardware channels. The AudioSources with lowest priority (and audibility) are virtualized first. Priority is an integer between 0 and 255. Where, 0 = high priority, 255 = low priority.
Declaration
public virtual int priority { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
recycleAfterUse
After the audio clip has finished playing, recycle the audio player and put it back in the pool
Declaration
public bool recycleAfterUse { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
referenceVolume
Volume value used as a reference when fading in or out the audio player's volume
Declaration
protected float referenceVolume { get; set; }
Property Value
Type | Description |
---|---|
Single |
reverbZoneMix
The amount by which the signal from this sound will be mixed into the global reverb associated with the Reverb Zones.
Declaration
public virtual float reverbZoneMix { get; set; }
Property Value
Type | Description |
---|---|
Single |
settings
Soundy global settings
Declaration
public static SoundySettings settings { get; }
Property Value
Type | Description |
---|---|
SoundySettings |
spatialBlend
Set how much this audio player is affected by 3D spatialisation calculations (attenuation, doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3.
Declaration
public virtual float spatialBlend { get; set; }
Property Value
Type | Description |
---|---|
Single |
spread
Set the spread angle (in degrees) of a 3d stereo or multichannel sound in speaker space
Declaration
public virtual float spread { get; set; }
Property Value
Type | Description |
---|---|
Single |
time
Playback position in seconds. Read current playback position, or seek to a new playback time. Be aware that this is not sample-exact seeking, but rather a best effort approximation depending on the audio format. On a compressed audio file, the seek point will likely not be exactly playable, and instead the actual seek point will be some time before or after the requested seek time.
Declaration
public abstract float time { get; set; }
Property Value
Type | Description |
---|---|
Single |
timeSamples
Playback position in PCM samples. This is a convenience wrapper for timeSamples / frequency. Use this to read current playback position, or to seek to a new playback position in samples (fractions rounded to nearest int). It is more precise than time when the clip is compressed.
Declaration
public virtual int timeSamples { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
volume
Volume of the audio player
Declaration
public virtual float volume { get; set; }
Property Value
Type | Description |
---|---|
Single |
Methods
Awake()
Declaration
protected virtual void Awake()
Dispose()
Dispose of this audio player and do not return it to the pool it came from. This is useful when you want to destroy the audio player and not return it to the pool, thus releasing its resources.
Declaration
public virtual void Dispose()
FadeInAndPlay()
Starts playing and fading in the volume of the audio player, if it is not currently playing. A fade in duration of 0 will play the audio player immediately.
Declaration
public void FadeInAndPlay()
FadeOutAndStop()
Starts fading out the volume of the audio player, if it is not currently playing, and then stops it when the fade out is finished. A fade out duration of 0 will stop the audio player immediately.
Declaration
public void FadeOutAndStop()
Finish()
Performs the necessary actions to either recycle it (by returning it to the pool) or to stop it.
Declaration
public virtual void Finish()
LoadMusic(MusicId)
Load the next audio clip from the given musicId
Declaration
public bool LoadMusic(MusicId musicId)
Parameters
Type | Name | Description |
---|---|---|
MusicId | musicId | The musicId to load the audio clip from |
Returns
Type | Description |
---|---|
Boolean | True if the audio clip was loaded, false otherwise |
LoadMusic(MusicObject, AudioMixerGroup)
Load the audio clip from the given music object. If the music object is null, this audio player will be stopped.
Declaration
public virtual bool LoadMusic(MusicObject musicObject, AudioMixerGroup audioMixerGroup = null)
Parameters
Type | Name | Description |
---|---|---|
MusicObject | musicObject | The music object to load the audio clip from |
AudioMixerGroup | audioMixerGroup | The output audio mixer group to use for the audio clip |
Returns
Type | Description |
---|---|
Boolean | True if the audio clip was loaded, false otherwise |
LoadMusic(String, String, AudioMixerGroup)
Load the audio clip from the given music library and music name. If the music library or music name is null, this audio player will be stopped.
Declaration
public bool LoadMusic(string libraryName, string musicName, AudioMixerGroup audioMixerGroup = null)
Parameters
Type | Name | Description |
---|---|---|
String | libraryName | The name of the music library to load the music from |
String | musicName | The name of the music to load |
AudioMixerGroup | audioMixerGroup | The output audio mixer group to use for the audio clip |
Returns
Type | Description |
---|---|
Boolean | True if the audio clip was loaded, false otherwise |
LoadSound(SoundId)
Load the next audio clip from the given soundId
Declaration
public bool LoadSound(SoundId soundId)
Parameters
Type | Name | Description |
---|---|---|
SoundId | soundId | The soundId to load the audio clip from |
Returns
Type | Description |
---|---|
Boolean | True if the audio clip was loaded, false otherwise |
LoadSound(SoundObject, AudioMixerGroup)
Load the next audio clip from the given sound object. If the sound object is null, or if it has no more clips to play, this audio player will be stopped.
Declaration
public virtual bool LoadSound(SoundObject soundObject, AudioMixerGroup audioMixerGroup = null)
Parameters
Type | Name | Description |
---|---|---|
SoundObject | soundObject | The sound object to load the next audio clip from |
AudioMixerGroup | audioMixerGroup | The output audio mixer group to use for the audio clip |
Returns
Type | Description |
---|---|
Boolean | True if the audio clip was loaded, false otherwise |
LoadSound(String, String, AudioMixerGroup)
Load the next audio clip from the given sound library and sound name. If the sound library or sound name is null, or if the sound library has no sound with the given name, this audio player will be stopped.
Declaration
public bool LoadSound(string libraryName, string soundName, AudioMixerGroup audioMixerGroup = null)
Parameters
Type | Name | Description |
---|---|---|
String | libraryName | The name of the sound library to load the sound from |
String | soundName | The name of the sound to load |
AudioMixerGroup | audioMixerGroup | The output audio mixer group to use for the audio clip |
Returns
Type | Description |
---|---|
Boolean | True if the audio clip was loaded, false otherwise |
Mute()
Mute the audio player
Declaration
public virtual void Mute()
OnDestroy()
Declaration
protected virtual void OnDestroy()
OnDisable()
Declaration
protected virtual void OnDisable()
OnEnable()
Declaration
protected virtual void OnEnable()
OnFinished()
Called when the audio player finished playing.
Declaration
protected virtual void OnFinished()
OnIdle()
Called when the audio player became idle.
Declaration
protected virtual void OnIdle()
OnPaused()
Called when the audio player was paused.
Declaration
protected virtual void OnPaused()
OnPlaying()
Called when the audio player started playing.
Declaration
protected virtual void OnPlaying()
OnResumed()
Called when the audio player was resumed.
Declaration
protected virtual void OnResumed()
OnStopped()
Called when the audio player was stopped.
Declaration
protected virtual void OnStopped()
Pause()
Pause the currently playing audio
Declaration
public virtual void Pause()
Play()
Play the currently set audio clip
Declaration
public virtual void Play()
ProcessFade(Single, Single, Single, UnityAction, UnityAction)
Internal IEnumerator used to fade in/out the audio player's volume
Declaration
protected IEnumerator ProcessFade(float duration, float fromVolume, float toVolume, UnityAction onFadeStartCallback, UnityAction onFadeFinishCallback)
Parameters
Type | Name | Description |
---|---|---|
Single | duration | |
Single | fromVolume | |
Single | toVolume | |
UnityAction | onFadeStartCallback | |
UnityAction | onFadeFinishCallback |
Returns
Type | Description |
---|---|
IEnumerator |
Recycle()
Return the audio player to the pool it came from
Declaration
public virtual void Recycle()
ResetAudioPlayer()
Reset the audio player to its default values
Declaration
public virtual void ResetAudioPlayer()
ResetCallbacks()
Reset the audio player callbacks to null
Declaration
public virtual void ResetCallbacks()
SetPlayState(PlayState)
Declaration
protected void SetPlayState(PlayState newPlayState)
Parameters
Type | Name | Description |
---|---|---|
PlayState | newPlayState |
SetPosition(Vector3)
Set the position, in world space, of this audio player
Declaration
public void SetPosition(Vector3 position)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | The position to set |
StartTicker()
Declaration
protected void StartTicker()
Stop()
Stop the currently playing audio
Declaration
public virtual void Stop()
StopFadeIn()
Stop the fade in process and update the isFadingIn flag to false
Declaration
protected void StopFadeIn()
StopFadeOut()
Stop the fade out process and update the isFadingOut flag to false
Declaration
protected void StopFadeOut()
StopTicker()
Declaration
protected void StopTicker()
Tick()
Called every frame to update the audio player's state. This is where the audio player is recycled if it is not in use. This method is timescale independent.
Declaration
protected virtual void Tick()
UnMute()
Unmute the audio player
Declaration
public virtual void UnMute()
UnPause()
Resume the currently paused audio
Declaration
public virtual void UnPause()