audio loop change during playback?

I'm using the new audio library and I want to give the user a button to turn looping on and off -- even during playback without having to restart the sound track. How do I implement this? I can only see one way to set the loop variable and that seems to be when in the audio.play() function.

I looked in the audio mixer and player sample apps but they don't seem to do what I want either -- just sets the loop for the next time the sound is played. This is a 30 minute sound track so I don't want to force them to start over in order to repeat the playback.

Instead of using the built-in looping feature, you could just do looping yourself. Set an onComplete callback and during the callback, use your own loop flag to decide whether you should rewind the stream and play again.

Thanks, thats exactly the conclusion I came to as well. That works very nicely so far. I have two more questions about audio:

  1. What is the state of the audio when we arrive in onComplete callback? I tried to do a rewind and resume but that didn't work. Should I audio.dispose() and then call audio.play()?
  2. How can I get the elapsed time on the track? I think it would be friendly to let the user know how much of the track has played and how much is remaining to go.

Thanks!

Good question. The state of the audio might be either stopped or playing. It probably is not paused so resume will have no effect. Try a [rewind and play], or [stop, rewind, play]. Don't dispose the audio.

This might have been discussed elsewhere on this forum, but there is no way to get this for now. A work around might be to keep track of time yourself since you now know when the song loops and when you start playing it again.

Thanks, that's very helpful. I'm hoping a time function will be added to the audio API on a future release :)

I'm noticing that when the screen blanks out on my device (iPod in this case) that my audio stops playing. In order to keep it playing I have to turn off the screen timeout. Is there a way to keep the audio going when the display times out?

views:1391 update:2011/10/2 9:44:12
corona forums © 2003-2011