I have the following script to play audio from an array:
var should_play = $PlaybackSwitch.active and source != null
if should_play:
var empty_frames = playback.get_frames_available()
while empty_frames > 0:
playback.push_frame(source.audio_data[playback_index])
playback_index += 1
empty_frames -= 1
if should_play and not $Player.playing:
playback.clear_buffer()
$Player.play()
if not should_play and $Player.playing:
$Player.stop()
playback_index = 0
But I have the problem that when I stop and restart playback, a snippet of audio from the end of what was previously playing makes it in. Calling clear_buffer
is supposed to help with this, but it produces the error Condition "active" is true
. Looking at the C++ source, I can't figure out where this is getting set. What do I need to do to make the stream not active
so I can clear it?