Fast forward and rewind buttons, or skip n seconds, for streaming mp3

We have an app where we play speaker texts. When the app is demonstrated, there’s a wish to skip through irrelevant portions of the speech to cut down on time taken to demonstrate the app.

Is it easy to make buttons to rewind/fast forward a few seconds?

I can’t access the documentation, but it seems seek() skips and rewind() skips to the start.

Also: does this work properly with (tested working) .mp3s on Iphone and Android?

We’re using audio.loadSound().

Hi @henrik5,

It should work, but can I please see some of your code? How long is the audio file?

Brent

function playCurrentSong(e)if e.phase=="ended" or e.phase=="tap" then if marker.x==startx then audio.rewind(song1) sec = 0 min = 0 end timerSource = timer.performWithDelay(1000, updateProgress, 0) audio.play(song1) playing = true updateInfo() playBtn.isVisible = false stopBtn.isVisible = true end return true end

The above code is bound to the Play button. UpdateInfo updates timestamp and UpdateProgress moves a marker on a line. 

Length ranges from 2 to 30 minutes.

@henrik what you want to use is audio.seek you will need a bit of simple maths to “move forward 5 seconds”.  Do pay attention to the gotchas though.

Hi Henrik,

Docs are back up: https://docs.coronalabs.com/api/library/audio/seek.html

If the audio is 2-30 minutes long, shouldn’t you be using “audio.loadStream()”? Preloading an audio file that’s 30 minutes long, no matter the audio quality, must mean a vast amount of memory taken up. I would highly recommend you don’t preload audio files longer than 1 minute.

Depending on the call, notice the docs state you must either seek by a channel number or the audio handle.

Brent

Actually checked the source properly before posting this time, and yes we use loadStream :wink: Thanks guys.

I already have a position tracker variable and a handle, so presumably I could add and subtract from that and use it for the absolute position, and skip by stopping, seeking and playing if seek returns true.

Hi @henrik5,

It should work, but can I please see some of your code? How long is the audio file?

Brent

function playCurrentSong(e)if e.phase=="ended" or e.phase=="tap" then if marker.x==startx then audio.rewind(song1) sec = 0 min = 0 end timerSource = timer.performWithDelay(1000, updateProgress, 0) audio.play(song1) playing = true updateInfo() playBtn.isVisible = false stopBtn.isVisible = true end return true end

The above code is bound to the Play button. UpdateInfo updates timestamp and UpdateProgress moves a marker on a line. 

Length ranges from 2 to 30 minutes.

@henrik what you want to use is audio.seek you will need a bit of simple maths to “move forward 5 seconds”.  Do pay attention to the gotchas though.

Hi Henrik,

Docs are back up: https://docs.coronalabs.com/api/library/audio/seek.html

If the audio is 2-30 minutes long, shouldn’t you be using “audio.loadStream()”? Preloading an audio file that’s 30 minutes long, no matter the audio quality, must mean a vast amount of memory taken up. I would highly recommend you don’t preload audio files longer than 1 minute.

Depending on the call, notice the docs state you must either seek by a channel number or the audio handle.

Brent

Actually checked the source properly before posting this time, and yes we use loadStream :wink: Thanks guys.

I already have a position tracker variable and a handle, so presumably I could add and subtract from that and use it for the absolute position, and skip by stopping, seeking and playing if seek returns true.