Using a StreamAudioPlayer with a Synchronized assigned and two songs (Song A, Song B), I'm trying make a crossfade between those songs using a Tween The problem is that the crossfade is not simultaneously, it fades out the Song A and after muting it, the Song B starts fading in.
I crossfade calling this function once:
@onready var music_player: AudioStreamPlayer = $MusicPlayer
func set_music(song: int =-1, crossfade: float = 0.0, position: float = -1.0) -> void:
var sync: AudioStreamSynchronized = music_player.stream
var old_son: int = active_song
sync.set_sync_stream_volume(song, -80.0)
active_song = song
var tween: Tween = create_tween()
tween.set_trans(Tween.TRANS_SINE)
tween.set_ease(Tween.EASE_IN_OUT)
tween.parallel().tween_method( \
func(v: float) -> void: sync.set_sync_stream_volume(old_son, v), \
sync.get_sync_stream_volume(old_son), \
-80.0, crossfade)
tween.parallel().tween_method( \
func(v: float) -> void: sync.set_sync_stream_volume(song, v), \
sync.get_sync_stream_volume(song), \
0.0, crossfade)