Skip to content

AudioPlayer

Shahriar Shahrabi edited this page May 12, 2020 · 2 revisions

AudioPlayer

A container derived from the Component class responsible for playing the audio in the scene. The Audio player holds an Audioclip which it plays through the AudioEngine once its Play function is called. The AudioPlayer is not responsible for the lifetime of the AudioClip, that is the job of the AudioAssembly class which loads these clips and destroys them at the appropriate time. Hence an AudioClip can be shared between several AudioPlayers.

ToyRenderer uses the SoLoud audio library. The underlying library holds way more functionality than what is currently exposed through the AudioPlayer, AudioEngine and AudioClip abstraction. As time goes on, more of this functionality will be exposed.


The main functions unique to the AudioPlayer class are:

Function Name Purpose
AudioPlayer(const char* AudioClipTagName, bool looped = false, bool autoPlay = false); The constructor used to set the AudioClip, whether it should be loop and whether it should play automatically
void Play() The call to play the audio based on the settings set on the AudioPlayer instance

The main member values unique to the AudioPlayer class are:

Member Value Name Purpose
AudioClip * m_AudioClip The clip which this player plays, no ownership over the pointer
bool m_looped Whether the audio should be looped
bool m_autoPlayer If it should automatically start beginning
bool m_3dSound Whether it is a 3D audio source. The 3D audio source uses the transform of the AudioPlayer gameobject to imitate the effect of a 3D sound, instead of a global 2D sound
Clone this wiki locally