Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioStreamPlayer.stop() does not stop playback if playback was started in the same frame #37148

Open
Tracked by #76797
KirsonWorks opened this issue Mar 18, 2020 · 8 comments

Comments

@KirsonWorks
Copy link

Godot version:
3.2.1

OS/device including version:
Windows 10 64-bit

Issue description:
AudioStreamPlayer does not stop playback if stream position is zero.

In my project sometimes there are situations when states change very quickly, one state plays sound effect, another stops it.

I found out that

$sfx.play()
$sfx.stop()

is not working as expected.

Steps to reproduce:
Add AudioStreamPlayer, load sound stream and execute play() stop() methods in once block.

Minimal reproduction project:
AudioStreamPlayerPlayStop.zip

@Anutrix
Copy link
Contributor

Anutrix commented Mar 19, 2020

It seems the call to stop is too quick.

$AudioStreamPlayer.play()
OS.delay_msec(15)
$AudioStreamPlayer.stop()

Delay of 15ms or more makes it work fine.
Delay of less than 15 ms doesn't work.
Note: I tested above on master and with my own project.

@Kirs-one Note: Your project has a sound which is too short. So it will have same reaction with and without stop.

@Calinou
Copy link
Member

Calinou commented Mar 19, 2020

@Anutrix $AudioStreamPlayer.call_deferred("stop") might be a cleaner, non-blocking way to do it, as it will exactly wait for 1 rendered frame before stopping.

@KirsonWorks
Copy link
Author

I tried both methods, but that didn't work.

@KirsonWorks
Copy link
Author

I use temporary solution:

# For playback.
if $AudioStreamPlayer.stream_paused:
	$AudioStreamPlayer.stop()
	$AudioStreamPlayer.stream_paused = false

$AudioStreamPlayer.play()

# For stopping.
$AudioStreamPlayer.stream_paused = true

@lijamez
Copy link

lijamez commented Jun 27, 2020

I just ran into this issue, which is still present in Godot 3.2.2

@Manx191
Copy link

Manx191 commented Jan 9, 2021

Does anyone know if there is a fix for this or a workaround?

I have tried all of the above and had no success.

Thanks

@Calinou
Copy link
Member

Calinou commented Jan 9, 2021

@Manx191 Depending on what you're trying to achieve, you may have more luck swapping out the stream resource to play a different sound (or setting it to null).

@KirsonWorks
Copy link
Author

KirsonWorks commented Jan 12, 2021

@Manx191
Try this:

$AudioStreamPlayer.stop()
$AudioStreamPlayer.seek(-1)

@Calinou Calinou changed the title AudioStreamPlayer does not stop playback AudioStreamPlayer.stop() does not stop playback if playback was started in the same frame Oct 5, 2021
Poobslag added a commit to Poobslag/turbofat that referenced this issue May 25, 2022
Fixed bug where pieces could lock in mid air with a squish move. This
would occur if the player exhausted all of the piece's lock resets and
then performed a squish move which left the piece in mid-air.

Fixed bug where squish sound effects would sometimes continue after the
squish was completed or cancelled. This was caused by Godot  #37148, a
bug which causes the 'AudioStreamPlayer.stop()' to malfunction if
playback was started in the same frame
(godotengine/godot#37148)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants