| 135 | } |
| 136 | |
| 137 | bool AudioSource::playBackground() { |
| 138 | AssertIf(_flags.isOn(Node::Cleanup), "can not operate on an invalid AudioSource"); |
| 139 | if (_handle != 0 && SharedAudio.isVoicePlaying(_handle)) { |
| 140 | return false; |
| 141 | } |
| 142 | _is3D = false; |
| 143 | if (auto audioFile = SharedAudioCache.load(_filename)) { |
| 144 | uint32_t busHandle = _bus ? _bus->getHandle() : 0; |
| 145 | _pan = 0.0f; |
| 146 | auto soloud = SharedAudio.getSoLoud(); |
| 147 | _handle = soloud->playBackground(*audioFile->getSource(), _volume, false, busHandle); |
| 148 | soloud->setProtectVoice(_handle, true); |
| 149 | if (_playSpeed != 1.0f) { |
| 150 | soloud->setRelativePlaySpeed(_handle, _playSpeed); |
| 151 | } |
| 152 | if (_loopStartTime > 0.0) { |
| 153 | soloud->setLoopPoint(_handle, _loopStartTime); |
| 154 | } |
| 155 | _protected = true; |
| 156 | WRef<AudioSource> self(this); |
| 157 | SharedAudio.addRef(_handle, audioFile, [self](uint32_t handle) { |
| 158 | if (self && self->_handle == handle) { |
| 159 | self->_handle = 0; |
| 160 | self->emit("AudioEnd"sv, handle); |
| 161 | if (self->_autoRemove) { |
| 162 | self->removeFromParent(); |
| 163 | } |
| 164 | } |
| 165 | }); |
| 166 | return true; |
| 167 | } |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | bool AudioSource::play(double delayTime) { |
| 172 | AssertIf(_flags.isOn(Node::Cleanup), "can not operate on an invalid AudioSource"); |
no test coverage detected