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 emits finished signal inconsistently. #56156

Open
Tracked by #76797
abdlquadri opened this issue Dec 22, 2021 · 8 comments
Open
Tracked by #76797

AudioStreamPlayer emits finished signal inconsistently. #56156

abdlquadri opened this issue Dec 22, 2021 · 8 comments

Comments

@abdlquadri
Copy link

Godot version

Godot_v4.0-dev.20211004_linux.64

System information

5.4.0-91-generic #102-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux

Issue description

Godot master branch emits finished signal inconsistently for different audio files.

Audios 001001.mp3, 001001.ogg does not emit finished while 002030.mp3 does emit.

Godot 3.4 behaves correctly. Meaning all files emit finished signal.

Steps to reproduce

Load project https://github.com/abdlquadri/GodotAudioPlayerSignalDemo/tree/main/TestingAudioPlayerSignals in Godot_v4.

Expect to see fini printed in console after audio stops.

This expected behavior is true for some files ( 002030.mp3) but not others (001001.mp3, 001001.ogg)

You can load https://github.com/abdlquadri/GodotAudioPlayerSignalDemo/tree/main/TestingAudioPlayerSignals_v3 in Godot_v3 to see that it works for Godot 3

Minimal reproduction project

https://github.com/abdlquadri/GodotAudioPlayerSignalDemo/tree/main/TestingAudioPlayerSignals

@abdlquadri abdlquadri changed the title Godot_v4.0-dev.20211004 emits finished signal inconsistently. Godot_v4.0-dev.20211004 AudioStreamPlayer emits finished signal inconsistently. Dec 22, 2021
@abdlquadri abdlquadri changed the title Godot_v4.0-dev.20211004 AudioStreamPlayer emits finished signal inconsistently. AudioStreamPlayer emits finished signal inconsistently. Dec 22, 2021
@Calinou Calinou added this to the 4.0 milestone Dec 22, 2021
@abdlquadri
Copy link
Author

Hi @Calinou , if I could be directed to where to look, I might be able to fix this issue myself. Thank you.

@Calinou
Copy link
Member

Calinou commented Dec 30, 2021

This is likely a regression from #51296.

The fix may be similar to #55808. See also #55570 which might have affected this.

@abdlquadri
Copy link
Author

Ok. Thanks. @Calinou

@lufog
Copy link
Contributor

lufog commented Apr 26, 2022

I understand absolutely nothing about audio stream processing. But after playing around with the debugger, and comparing the behavior when playing mp3 and ogg files.

I noticed the following:

When playing mp3 file, the is_playback_active(playback) returns false at the end. Which results in the line 49 being executed:

if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
}

But when playing ogg file, is_playback_active(playback) always returns true, line 49 is not executed. So playbacks_to_remove is always empty, and this code is never executed:

if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}

@lufog
Copy link
Contributor

lufog commented Apr 27, 2022

The emission of the finished signal depends on the length or bit depth of the audio file. For example, in this test project, when playing 6 mp3 files of different bit depth, the finished signal is emitted for only one.

AudioPlayerSignalTest.zip

@pierpo
Copy link

pierpo commented Feb 14, 2023

Anyone looking at this issue? 😊

@ellenhp Since it could be related to your past work on the audio, would you have an idea of a possible cause?
I hope it's okay to ping you, I have no idea if it's acceptable behavior to do such a thing. Of course I'm not asking for you to look into it directly, I'm just asking for some guesses if you can think of any 😊

We'd love to know if there's at least a workaround 😉
And maybe dive into it, with some indications!

@croked91
Copy link

croked91 commented Sep 20, 2023

Hi, if somebody else has this problem, try my trick. Yes, it's not ideal solution, but it's works:

class_name AudioPlayer
extends AudioStreamPlayer

signal audio_finished


@onready var check_track_finished_timer := Timer.new()


func _ready() -> void:
	add_child(check_track_finished_timer)
	audio_finished.connect(_some_func)

func play_track() -> void:
	...
	_check_is_finished()
	await audio_finished
	...

func  _some_func() -> void:
	....

func _check_is_finished() -> void:
	if not playing:
		audio_finished.emit()
		check_track_finished_timer.stop()
		return
	check_track_finished_timer.timeout.connect(_check_is_finished)
	check_track_finished_timer.start(0.5)

Just example. If you have any questions or comments, I will be happy to answer.

@YuriSizov YuriSizov modified the milestones: 4.2, 4.3 Nov 15, 2023
@KoBeWi KoBeWi modified the milestones: 4.3, 4.x Aug 3, 2024
@amarraff
Copy link

amarraff commented Oct 16, 2024

Found this issue after engaging with pull request #87830.

This bug is directly caused by setting an audio clip's "loop" property to "true". I am using v4.3.stable.official [77dcf97]. Hopefully that can help a fix be found. Can work around this by setting the loop property to false and looping manually.

I wanted to await for the finished signal at the end of a looping audiostream before running some code. I ended up restructuring my code to function differently, but it'd be great if this issue could be fixed. The "finished" signal appears to still fire, you can connect a function to the signal and it'll receive it. But, using await doesn't work. The code will never continue.

I noticed that AudioStreamPlayer now has "Parameters -> Looping" but I cannot figure out how to set this via code, it's not mentioned in the docs. I tried "audio_player.looping = true", "audio_player.looping.on = true", and "audio_player.set_parameter("looping",true)". But, all of these return errors. Information on how to utilize this feature would be appreciated.

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

9 participants