Open cbscribe opened 3 years ago
The webpage states the problem as "You’ve tried adding an AudioStreamPlayer to your mob/coin/etc. to play when the object dies or is collected. But the problem is that when you remove the object, the audio player goes with it, chopping off the sound. You need an easier way to manage playing audio."
However, the solution solves more than this problem.
The problem as stated could be solved simply by having the AudioStreamPlayer elsewhere in the scenetree that doesn't get removed when the mob/coin etc gets removed. That would be the simplest way.
The given solution also solves the problem that a sound can cut off another sound if played on the same AudioStreamPlayer, hence if, for example, multiple coins are collected in rapid succession, their full sound will not be heard (except for the last one) because each cuts off the one before.
I think the webpage should be updated to redefine the problem as two separate problems: (1) When a node is removed (i.e., with queue_free()), it will cut off a sound if the sound is currently playing with an AudioStreamPlayer that is a child of that node. (2) Sounds played with the same AudioStreamPlayer cut off sounds that are already playing.
Your example project works perfectly, but when I adapt this to a project of mine it plays 8 sounds perfectly then silence as if _on_stream_finished is not being called. Is there something else I have to do to make sure this function gets called?
How do you stop the audio if it's set to loop? Example: background music
Discussion for http://godotrecipes.com/audio/audio_manager/