This is just weird. I’m playing a sound and at some point before it ends, the code fades out the gain with go.animate. Afterwards, the sound cannot be played again.
Here is minimal code that I think should work, but doesn’t.
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1 })
sound.play("/music#waggs away", {gain=0.3})
timer.delay(10, false, FadeOut)
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
print("Play again!")
sound.stop("/music#waggs away")
sound.play("/music#waggs away", {gain=0.3})
end
end
function FadeOut(self)
go.animate("/music#waggs away", "gain", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, 6, 0, CleanUpAnimate)
end
function CleanUpAnimate(self)
go.cancel_animations("/music#waggs away", 'gain')
print('Click to play sound again.')
end
NOTE: Do not click the mouse until the sound’s first play is fully complete.
Also, notice that when the animate call is made, the sound’s volume jumps louder before fading.