You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Fix audio player not resetting after wav finishes
This commit is contained in:
@@ -105,6 +105,8 @@ void AudioStreamEditor::_audio_changed() {
|
|||||||
|
|
||||||
void AudioStreamEditor::_play() {
|
void AudioStreamEditor::_play() {
|
||||||
if (_player->is_playing()) {
|
if (_player->is_playing()) {
|
||||||
|
// '_pausing' variable indicates that we want to pause the audio player, not stop it. See '_on_finished()'.
|
||||||
|
_pausing = true;
|
||||||
_player->stop();
|
_player->stop();
|
||||||
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
||||||
set_process(false);
|
set_process(false);
|
||||||
@@ -125,10 +127,13 @@ void AudioStreamEditor::_stop() {
|
|||||||
|
|
||||||
void AudioStreamEditor::_on_finished() {
|
void AudioStreamEditor::_on_finished() {
|
||||||
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
_play_button->set_icon(get_theme_icon("MainPlay", "EditorIcons"));
|
||||||
if (_current == _player->get_stream()->get_length()) {
|
if (!_pausing) {
|
||||||
_current = 0;
|
_current = 0;
|
||||||
_indicator->update();
|
_indicator->update();
|
||||||
|
} else {
|
||||||
|
_pausing = false;
|
||||||
}
|
}
|
||||||
|
set_process(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioStreamEditor::_draw_indicator() {
|
void AudioStreamEditor::_draw_indicator() {
|
||||||
@@ -194,8 +199,6 @@ void AudioStreamEditor::_bind_methods() {
|
|||||||
|
|
||||||
AudioStreamEditor::AudioStreamEditor() {
|
AudioStreamEditor::AudioStreamEditor() {
|
||||||
set_custom_minimum_size(Size2(1, 100) * EDSCALE);
|
set_custom_minimum_size(Size2(1, 100) * EDSCALE);
|
||||||
_current = 0;
|
|
||||||
_dragging = false;
|
|
||||||
|
|
||||||
_player = memnew(AudioStreamPlayer);
|
_player = memnew(AudioStreamPlayer);
|
||||||
_player->connect("finished", callable_mp(this, &AudioStreamEditor::_on_finished));
|
_player->connect("finished", callable_mp(this, &AudioStreamEditor::_on_finished));
|
||||||
|
|||||||
@@ -41,17 +41,18 @@ class AudioStreamEditor : public ColorRect {
|
|||||||
GDCLASS(AudioStreamEditor, ColorRect);
|
GDCLASS(AudioStreamEditor, ColorRect);
|
||||||
|
|
||||||
Ref<AudioStream> stream;
|
Ref<AudioStream> stream;
|
||||||
AudioStreamPlayer *_player;
|
AudioStreamPlayer *_player = nullptr;
|
||||||
ColorRect *_preview;
|
ColorRect *_preview = nullptr;
|
||||||
Control *_indicator;
|
Control *_indicator = nullptr;
|
||||||
Label *_current_label;
|
Label *_current_label = nullptr;
|
||||||
Label *_duration_label;
|
Label *_duration_label = nullptr;
|
||||||
|
|
||||||
Button *_play_button;
|
Button *_play_button = nullptr;
|
||||||
Button *_stop_button;
|
Button *_stop_button = nullptr;
|
||||||
|
|
||||||
float _current;
|
float _current = 0;
|
||||||
bool _dragging;
|
bool _dragging = false;
|
||||||
|
bool _pausing = false;
|
||||||
|
|
||||||
void _audio_changed();
|
void _audio_changed();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user