Exposes interactive audio playback current playing clip.

This commit is contained in:
Gustavo Jaruga Cruz 2024-08-19 02:51:07 -03:00
parent 1bd740d18d
commit 12f682bdc2
3 changed files with 18 additions and 0 deletions

View File

@ -1011,6 +1011,10 @@ void AudioStreamPlaybackInteractive::switch_to_clip(int p_index) {
switch_request = p_index;
}
int AudioStreamPlaybackInteractive::get_current_clip_index() const {
return playback_current;
}
int AudioStreamPlaybackInteractive::get_loop_count() const {
return 0; // Looping not supported
}
@ -1026,4 +1030,5 @@ bool AudioStreamPlaybackInteractive::is_playing() const {
void AudioStreamPlaybackInteractive::_bind_methods() {
ClassDB::bind_method(D_METHOD("switch_to_clip_by_name", "clip_name"), &AudioStreamPlaybackInteractive::switch_to_clip_by_name);
ClassDB::bind_method(D_METHOD("switch_to_clip", "clip_index"), &AudioStreamPlaybackInteractive::switch_to_clip);
ClassDB::bind_method(D_METHOD("get_current_clip_index"), &AudioStreamPlaybackInteractive::get_current_clip_index);
}

View File

@ -259,6 +259,7 @@ public:
void switch_to_clip_by_name(const StringName &p_name);
void switch_to_clip(int p_index);
int get_current_clip_index() const;
virtual void set_parameter(const StringName &p_name, const Variant &p_value) override;
virtual Variant get_parameter(const StringName &p_name) const override;

View File

@ -9,6 +9,18 @@
<tutorials>
</tutorials>
<methods>
<method name="get_current_clip_index" qualifiers="const">
<return type="int" />
<description>
Return the index of the currently playing clip. You can use this to get the name of the currently playing clip with [method AudioStreamInteractive.get_clip_name].
[b]Example:[/b] Get the currently playing clip name from inside an [AudioStreamPlayer] node.
[codeblocks]
[gdscript]
var playing_clip_name = stream.get_clip_name(get_stream_playback().get_current_clip_index())
[/gdscript]
[/codeblocks]
</description>
</method>
<method name="switch_to_clip">
<return type="void" />
<param index="0" name="clip_index" type="int" />