From 99cbcd250a6b837da03ebfd6fc57cf767dd39f41 Mon Sep 17 00:00:00 2001 From: Micky Date: Wed, 27 Nov 2024 16:02:46 +0100 Subject: [PATCH] Fix AudioStreamPlayer2D/3D's `get_playback_position` returning `0` right after calling `seek` --- scene/2d/audio_stream_player_2d.cpp | 3 +++ scene/3d/audio_stream_player_3d.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 8aaa230075e..c1a40a817d9 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -253,6 +253,9 @@ bool AudioStreamPlayer2D::is_playing() const { } float AudioStreamPlayer2D::get_playback_position() { + if (setplay.get() >= 0) { + return setplay.get(); // play() has been called this frame, but no playback exists just yet. + } return internal->get_playback_position(); } diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index eb75650399d..19d241c8fa1 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -582,6 +582,9 @@ bool AudioStreamPlayer3D::is_playing() const { } float AudioStreamPlayer3D::get_playback_position() { + if (setplay.get() >= 0) { + return setplay.get(); // play() has been called this frame, but no playback exists just yet. + } return internal->get_playback_position(); }