diff options
| author | Yahkub-R <62478788+Yahkub-R@users.noreply.github.com> | 2024-08-06 09:46:37 -0400 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-16 16:41:06 +0200 |
| commit | 2b4ade1ed605bcbc85bbb5beaacd0f77831270c4 (patch) | |
| tree | d0fe2b0f7c90e72593d753fbc35f56db90742cf3 /servers | |
| parent | 562e583872036ea9e3683e447f85e94791b2ecc4 (diff) | |
| download | redot-engine-2b4ade1ed605bcbc85bbb5beaacd0f77831270c4.tar.gz | |
Fix AudioStreamPlayer get_playback_position() for web build
(cherry picked from commit bcd776e44174677f1995a49b697f9651f1f692ec)
Diffstat (limited to 'servers')
| -rw-r--r-- | servers/audio_server.cpp | 11 | ||||
| -rw-r--r-- | servers/audio_server.h | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 54840adcae..f0f894d03b 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -1379,6 +1379,12 @@ bool AudioServer::is_playback_active(Ref<AudioStreamPlayback> p_playback) { float AudioServer::get_playback_position(Ref<AudioStreamPlayback> p_playback) { ERR_FAIL_COND_V(p_playback.is_null(), 0); + // Samples. + if (p_playback->get_is_sample() && p_playback->get_sample_playback().is_valid()) { + Ref<AudioSamplePlayback> sample_playback = p_playback->get_sample_playback(); + return AudioServer::get_singleton()->get_sample_playback_position(sample_playback); + } + AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback); if (!playback_node) { return 0; @@ -1847,6 +1853,11 @@ bool AudioServer::is_sample_playback_active(const Ref<AudioSamplePlayback> &p_pl return AudioDriver::get_singleton()->is_sample_playback_active(p_playback); } +double AudioServer::get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback) { + ERR_FAIL_COND_V_MSG(p_playback.is_null(), false, "Parameter p_playback is null."); + return AudioDriver::get_singleton()->get_sample_playback_position(p_playback); +} + void AudioServer::update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale) { ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null."); return AudioDriver::get_singleton()->update_sample_playback_pitch_scale(p_playback, p_pitch_scale); diff --git a/servers/audio_server.h b/servers/audio_server.h index fd6cdb451e..2d6fc60860 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -141,6 +141,7 @@ public: virtual void stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {} virtual void set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused) {} virtual bool is_sample_playback_active(const Ref<AudioSamplePlayback> &p_playback) { return false; } + virtual double get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback) { return false; } virtual void update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale = 0.0f) {} virtual void set_sample_playback_bus_volumes_linear(const Ref<AudioSamplePlayback> &p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes) {} @@ -484,6 +485,7 @@ public: void stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback); void set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused); bool is_sample_playback_active(const Ref<AudioSamplePlayback> &p_playback); + double get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback); void update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale = 0.0f); AudioServer(); |
