Fix audio player not resetting after wav finishes
(cherry picked from commit daa62ccaa3
)
This commit is contained in:
parent
d5a2fd4e17
commit
ba70958b29
|
@ -109,6 +109,8 @@ void AudioStreamEditor::_changed_callback(Object *p_changed, const char *p_prop)
|
|||
void AudioStreamEditor::_play() {
|
||||
|
||||
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();
|
||||
_play_button->set_icon(get_icon("MainPlay", "EditorIcons"));
|
||||
set_process(false);
|
||||
|
@ -131,10 +133,13 @@ void AudioStreamEditor::_stop() {
|
|||
void AudioStreamEditor::_on_finished() {
|
||||
|
||||
_play_button->set_icon(get_icon("MainPlay", "EditorIcons"));
|
||||
if (_current == _player->get_stream()->get_length()) {
|
||||
if (!_pausing) {
|
||||
_current = 0;
|
||||
_indicator->update();
|
||||
} else {
|
||||
_pausing = false;
|
||||
}
|
||||
set_process(false);
|
||||
}
|
||||
|
||||
void AudioStreamEditor::_draw_indicator() {
|
||||
|
@ -210,8 +215,6 @@ void AudioStreamEditor::_bind_methods() {
|
|||
AudioStreamEditor::AudioStreamEditor() {
|
||||
|
||||
set_custom_minimum_size(Size2(1, 100) * EDSCALE);
|
||||
_current = 0;
|
||||
_dragging = false;
|
||||
|
||||
_player = memnew(AudioStreamPlayer);
|
||||
_player->connect("finished", this, "_on_finished");
|
||||
|
|
|
@ -42,17 +42,18 @@ class AudioStreamEditor : public ColorRect {
|
|||
GDCLASS(AudioStreamEditor, ColorRect);
|
||||
|
||||
Ref<AudioStream> stream;
|
||||
AudioStreamPlayer *_player;
|
||||
ColorRect *_preview;
|
||||
Control *_indicator;
|
||||
Label *_current_label;
|
||||
Label *_duration_label;
|
||||
AudioStreamPlayer *_player = nullptr;
|
||||
ColorRect *_preview = nullptr;
|
||||
Control *_indicator = nullptr;
|
||||
Label *_current_label = nullptr;
|
||||
Label *_duration_label = nullptr;
|
||||
|
||||
ToolButton *_play_button;
|
||||
ToolButton *_stop_button;
|
||||
ToolButton *_play_button = nullptr;
|
||||
ToolButton *_stop_button = nullptr;
|
||||
|
||||
float _current;
|
||||
bool _dragging;
|
||||
float _current = 0;
|
||||
bool _dragging = false;
|
||||
bool _pausing = false;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
|
Loading…
Reference in a new issue