0 votes

EDIT: Problem solved! I ended up hard-coding emit_signal("finished") into the "func process(delta: float)" function in the AudioStreamPlayer.gd code and it worked like a charm! Next track plays, update message triggers, everyone is happy. Leaving this post here in case anyone else has troubles and needs help debugging. Woot!

func _process(delta: float) -> void:
if not audio_player.is_playing():
    emit_signal("finished")

Hi fellow programmers --

I'm debugging an AudioStreamPlayer issue. I'm new to Godot, so there could be something I'm missing. Using Godot 3.2.3.stable.

Goal: have a playlist of music running in the background that plays the next song in the playlist when the first one ends.

Steps: Created playlist (unique var for each song), added a finished() signal via Node > Signals to trigger next song cueing & playback.

Results:

Initially, only 1 song from a background music playlist in a game was looping over and over. So read about how to de-loop the OGG files, then did that.

After this change, the initial song would play and then stop.

I've de-looped the OGG files & reimported multiple times, rewritten code over and over to figure out what's going on. What I'm seeing is that finished() signal is not firing at all. Not only is it not triggering the onAudioStreamPlayerfinished() in the AudioStreamPlayer script, it's not triggering the _onAudioStreamPlayer_finished() test call to a different node that is supposed to pass a "this has triggered successfully!" message in the main game.

the .call_deferred("play") method works fine to play the initial song, but doesn't appear to have fixed the issue of not triggering the next song in the list.

I've updated to test with WAV files as well, but getting the same error. The finished() signal is NOT firing.

Code from the AudioStreamPlayer script:

extends AudioStreamPlayer

onready var audio_player = AudioStreamPlayer.new()

var song0 = load("res://music/Example.ogg")
var song1 = load("res://music/Bonfire+-+320bit.ogg")
var song2 = load("res://music/Behind-the-Sword-320bit.ogg")
var song3 = load("res://music/Entertainment-320bit.ogg")
var song4 = load("res://music/Gjallar+-+320bit.ogg")
var song5 = load("res://music/Now+We+Feast+-+320bit.ogg")
var song6 = load("res://music/Vopna+-+320bit.ogg")
var which_song = 0

func _ready() -> void:
    cue_play_next()

func _on_AudioStreamPlayer_finished() -> void:
    which_song += 1
    var which_child = self.get_children()
    self.remove_child(which_child)
    cue_play_next()

func cue_play_next():
    if which_song == 7:
        which_song = 1
    if which_song == 0:
        audio_player.stream = song0
    if which_song == 1:
        audio_player.stream = song1
    if which_song == 2:
        audio_player.stream = song2
    if which_song == 3:
        audio_player.stream = song3
    if which_song == 4:
        audio_player.stream = song4
    if which_song == 5:
        audio_player.stream = song5
    if which_song == 6:
        audio_player.stream = song6
    self.add_child(audio_player)
#   audio_player.play()
    audio_player.call_deferred("play")

I'm at a loss. Any ideas/help?

Godot version 3.2.3.stable
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.