[Resolved] Loop rotation while sound plays

Trying to keep an object rotating (or any other movement) while a piece of music is playing.
I tried using

while isChannel1Active do

but this seems to hog memory and quickly crash the simulator.

What I need is a means to constantly check if the audio is still playing and keep changing the rotation while it plays.

Any ideas? [import]uid: 120570 topic_id: 30557 reply_id: 330557[/import]

Hi there,

Out of curiosity, what will cause the audio to stop playing? If it stops because of something your user does, then you would just place your code to stop the rotation in the same place where you respond to the user action to stop the audio. If the audio stops because the track is over and you’re not looping it, presumably you know how long the track is, so you could use a timer.performWithDelay when the audio starts for the length of the track, to stop the rotation the appropriate amount of time later. [import]uid: 109711 topic_id: 30557 reply_id: 122413[/import]

A click will stop it, sure. But I’m not looping it.
Lots of different pieces of music, variable lengths.
[import]uid: 120570 topic_id: 30557 reply_id: 122414[/import]

Hi there,

Try checking out the onComplete parameter of audio.play(). You can provide a function that will run when the audio finishes playing, and in that function you would stop the rotation. [import]uid: 109711 topic_id: 30557 reply_id: 122427[/import]

Great idea, works just fine. Thanks [import]uid: 120570 topic_id: 30557 reply_id: 122505[/import]

Hi there,

Out of curiosity, what will cause the audio to stop playing? If it stops because of something your user does, then you would just place your code to stop the rotation in the same place where you respond to the user action to stop the audio. If the audio stops because the track is over and you’re not looping it, presumably you know how long the track is, so you could use a timer.performWithDelay when the audio starts for the length of the track, to stop the rotation the appropriate amount of time later. [import]uid: 109711 topic_id: 30557 reply_id: 122413[/import]

A click will stop it, sure. But I’m not looping it.
Lots of different pieces of music, variable lengths.
[import]uid: 120570 topic_id: 30557 reply_id: 122414[/import]

Hi there,

Try checking out the onComplete parameter of audio.play(). You can provide a function that will run when the audio finishes playing, and in that function you would stop the rotation. [import]uid: 109711 topic_id: 30557 reply_id: 122427[/import]

Great idea, works just fine. Thanks [import]uid: 120570 topic_id: 30557 reply_id: 122505[/import]