MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Play

Method Play

Source/Engine/Audio/AudioSource.cpp:119–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119void AudioSource::Play()
120{
121 auto state = _state;
122 if (state == States::Playing)
123 return;
124 PROFILE_CPU();
125 if (Clip == nullptr || Clip->WaitForLoaded())
126 {
127 LOG(Warning, "Cannot play audio source without a clip ({0})", GetNamePath());
128 return;
129 }
130
131 if (SourceID == 0)
132 {
133 // Create audio source
134 SourceID = AudioBackend::Source::Add(Clip->Info(), GetPosition(), GetOrientation(), GetVolume(), GetPitch(), GetPan(), GetIsLooping() && !UseStreaming(), Is3D(), GetAttenuation(), GetMinDistance(), GetDopplerFactor());
135 if (SourceID == 0)
136 {
137 LOG(Warning, "Cannot create audio source ({0})", GetNamePath());
138 return;
139 }
140 }
141
142 _state = States::Playing;
143 _isActuallyPlayingSth = false;
144
145 // Audio clips with disabled streaming are controlled by audio source, otherwise streaming manager will play it
146 if (Clip->IsStreamable())
147 {
148 if (state == States::Paused)
149 {
150 // Resume
151 PlayInternal();
152 }
153 else
154 {
155 // Request faster streaming update
156 Clip->RequestStreamingUpdate();
157
158 // If we are looping and streaming also update streaming buffers
159 if (_loop || state == States::Stopped)
160 RequestStreamingBuffersUpdate();
161 }
162 }
163 else if (SourceID)
164 {
165 // Play it right away
166 AudioBackend::Source::SetNonStreamingBuffer(SourceID, Clip->Buffers[0]);
167 PlayInternal();
168 }
169 else
170 {
171 // Source was not properly added to the Audio Backend
172 LOG(Warning, "Cannot play uninitialized audio source.");
173 }
174}
175
176void AudioSource::Pause()

Callers 1

RebuildSourcesFunction · 0.45

Calls 14

GetOrientationFunction · 0.85
GetPitchFunction · 0.85
GetPanFunction · 0.85
Is3DFunction · 0.85
GetAttenuationFunction · 0.85
GetDopplerFactorFunction · 0.85
WaitForLoadedMethod · 0.80
GetVolumeFunction · 0.70
GetIsLoopingFunction · 0.70
GetMinDistanceFunction · 0.70
AddFunction · 0.50

Tested by

no test coverage detected