Skip to content

Allow a stream keep playing after its owner AudioStreamPlayer gets freed #12739

Open
@Lazy-Rabbit-2001

Description

@Lazy-Rabbit-2001

Describe the project you are working on

Godot games

Describe the problem or limitation you are having in your project

This has been bothering me, maybe most of us, for a very long period when a stream gets cut off and stopped unexpected when its player gets freed from the scene tree. Sometimes we hope there is a way to solve that problem -- allowing the stream to keep playing even though its owner player is freed before.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Introduce a playback_keep_after_deletion property (maybe other names but I cannot think of a better one, XP), including:

PLAYBACK_KEEP_DEFAULT # Default behavior, gets stopped when the player gets freed.
PLAYBACK_KEEP_TILL_FINISHED # Will stop when it is finished.
PLAYBACK_KEEP_TILL_SCENE_REMOVED # Will stop when it is finished or the scene is changed.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I checked the code, and found that there is a AudioStreamPlayerInternal, and maybe we can tweak its NOTIFICATION_EXIT_TREE, NOTIFICATION_PREDELETE to have better control of the behavior other than default one.

  • To avoid it gets stopped, only when the keeping mode is default can the sound be paused in NOTIFICATION_EXIT_TREE.
  • To avoid clearing the stream_playbacks that will lead to unexpected stop, we can check if it is default mode. If it is, do default behavior; otherwise, do special control of the internal player.
  • Since the player node will be freed before the internal player will be done so, we must change the process source, when the node is about to be freed, from the node to its scene tree so that the internal player will keep playing the sound correctly.
  • For PLAYBACK_KEEP_TILL_SCENE_REMOVED mode, we probably have to connect its signal that will be emitted on the current scene getting deleted, to the corresponding method.
  • Since the destructor of the audio stream player will also delete the internal player, which will cause unexpected stop as well, we have to declare and define a special free method for the internal player to safely free it rather than direct deletion.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, as you can reparent an audio stream player to other nodes that is existing. However, I don't think it worth making wheels and boilerplates for a frequently needed feature. So why not integrate it and make this feature out-of-box?

Is there a reason why this should be core and not an add-on in the asset library?

It's part of core features.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions