Merge pull request #65367 from Mickeon/fix-audio-stream-player-exiting-tree

Fix AudioStreamPlayer not resuming after returning to SceneTree
This commit is contained in:
Rémi Verschelde 2022-09-06 17:00:29 +02:00
commit 1a1fdf78e7
3 changed files with 17 additions and 2 deletions

View file

@ -43,13 +43,18 @@ void AudioStreamPlayer2D::_notification(int p_what) {
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
set_stream_paused(false);
} break;
case NOTIFICATION_EXIT_TREE: {
stop();
set_stream_paused(true);
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
} break;
case NOTIFICATION_PREDELETE: {
stop();
} break;
case NOTIFICATION_PAUSED: {
if (!can_process()) {
// Node can't process so we start fading out to silence.

View file

@ -247,13 +247,18 @@ void AudioStreamPlayer3D::_notification(int p_what) {
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
set_stream_paused(false);
} break;
case NOTIFICATION_EXIT_TREE: {
stop();
set_stream_paused(true);
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
} break;
case NOTIFICATION_PREDELETE: {
stop();
} break;
case NOTIFICATION_PAUSED: {
if (!can_process()) {
// Node can't process so we start fading out to silence.

View file

@ -40,6 +40,7 @@ void AudioStreamPlayer::_notification(int p_what) {
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
set_stream_paused(false);
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
@ -64,6 +65,10 @@ void AudioStreamPlayer::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
set_stream_paused(true);
} break;
case NOTIFICATION_PREDELETE: {
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
AudioServer::get_singleton()->stop_playback_stream(playback);
}