Audio is playing = false is there something like that

I have 2 buttons in the same app (screen)

buttonA – plays a big.mp3 file

buttonB – plays small.mp3 file


When I press buttonA I hear the mp3 fine, but if a user

press the buttonB right away, then I have the 2 mp3 files overlapping

that sounds bad.


I have the same buttons showing text

textA

textB


I use this

local function spanishListener () audio.play (audio1s) tx1.isVisible = true tx1e.isVisible = false end

So if the textA is visible I just change it for = true or = false

so I don’t see the 2 texts at the same time.


How do I solve the problem of the 2 audio files.?

is there something like audio.isPlaying = true or false

or how do I solve this problem?

Thanks for all your help

audio.play has onComplete parameter, so you can assing function to it which will make both buttons visible again :slight_smile:

Documentation is programmer’s first and best friend :slight_smile:http://docs.coronalabs.com/api/library/audio/play.html

Thanks I read that, but I don’t want the buttons to be visible or not visible.

I explain myself wrong.

When I press buttonA I hear an mp3 file playing – la la  la la la la la

When I press buttonB I hear another mp3 playing – tu tu tu tu tu tu tu tu

What I need is a way of detecting

if – the audioA is playing – la la la la la – then

  and I press buttonB

  first stop audioA, no more la la la la la

  now you can play tu tu tu tu tu

if no audioA is playing

  no problem, just play audioB

end

Something like that

What you do inside is up to you. Use some flags, and unlock it on complete

Thanks piotrz55

I did not really understand what you said by

“Use some flags, and unlock it on complete”

I never heard of the word “flags” in corona…

and then “unlock it” I did not get it…sorry

You see, I told you, I am not that advanced yet.

When he says “flags” I think he simply means use some form of conditional logic for when you want to play/stop a song.

In your previous post you basically answered your own question. :slight_smile:

" if – the audioA is playing – la la la la la – then   and I press buttonB   first stop audioA, no more la la la la la   now you can play tu tu tu tu tu if no audioA is playing   no problem, just play audioB end"  

You could call a function ( when a button is pressed ) that has some conditional logic, like what you say.
And you could do it several different ways - use audio.stop for when you want to stop a song that is playing, and then have it start the song of the button that was just pressed or a different method could be just waiting until the current song is finished and then start the song of the button that was recently pressed.

Also take a look at the example in the audio.play docs, specifically how event.completed is used.

Thanks for all the information.

I solved the problem, using {channel=1} or {channel=2}

like this

spanish = display.newImage("buttonSpanish.png") group:insert(spanish) spanish.x = 920; spanish.y = 100 local function spanishListener () audio.stop (2) audio.play (bgAudio, {channel=1}) tx1.isVisible = true tx1e.isVisible = false end spanish:addEventListener("tap", spanishListener)

first I put channel 1 for one mp3

then channel 2 for the other mp3

In the same function that I play the audio, I stop the other audio first.

In the function where I play channel 1, I stop channel 2 first

and then play audio 1.

And I did the same thing with the other function.

Done!!!

You see…thanks to all of you I’m learning a lot

I only have 6 months doing this…

2 apps in the app store

1 it’s almost there

and I’m working on my No. 4 app

Thank you one more time!!!

audio.play has onComplete parameter, so you can assing function to it which will make both buttons visible again :slight_smile:

Documentation is programmer’s first and best friend :slight_smile:http://docs.coronalabs.com/api/library/audio/play.html

Thanks I read that, but I don’t want the buttons to be visible or not visible.

I explain myself wrong.

When I press buttonA I hear an mp3 file playing – la la  la la la la la

When I press buttonB I hear another mp3 playing – tu tu tu tu tu tu tu tu

What I need is a way of detecting

if – the audioA is playing – la la la la la – then

  and I press buttonB

  first stop audioA, no more la la la la la

  now you can play tu tu tu tu tu

if no audioA is playing

  no problem, just play audioB

end

Something like that

What you do inside is up to you. Use some flags, and unlock it on complete

Thanks piotrz55

I did not really understand what you said by

“Use some flags, and unlock it on complete”

I never heard of the word “flags” in corona…

and then “unlock it” I did not get it…sorry

You see, I told you, I am not that advanced yet.

When he says “flags” I think he simply means use some form of conditional logic for when you want to play/stop a song.

In your previous post you basically answered your own question. :slight_smile:

" if – the audioA is playing – la la la la la – then   and I press buttonB   first stop audioA, no more la la la la la   now you can play tu tu tu tu tu if no audioA is playing   no problem, just play audioB end"  

You could call a function ( when a button is pressed ) that has some conditional logic, like what you say.
And you could do it several different ways - use audio.stop for when you want to stop a song that is playing, and then have it start the song of the button that was just pressed or a different method could be just waiting until the current song is finished and then start the song of the button that was recently pressed.

Also take a look at the example in the audio.play docs, specifically how event.completed is used.

Thanks for all the information.

I solved the problem, using {channel=1} or {channel=2}

like this

spanish = display.newImage("buttonSpanish.png") group:insert(spanish) spanish.x = 920; spanish.y = 100 local function spanishListener () audio.stop (2) audio.play (bgAudio, {channel=1}) tx1.isVisible = true tx1e.isVisible = false end spanish:addEventListener("tap", spanishListener)

first I put channel 1 for one mp3

then channel 2 for the other mp3

In the same function that I play the audio, I stop the other audio first.

In the function where I play channel 1, I stop channel 2 first

and then play audio 1.

And I did the same thing with the other function.

Done!!!

You see…thanks to all of you I’m learning a lot

I only have 6 months doing this…

2 apps in the app store

1 it’s almost there

and I’m working on my No. 4 app

Thank you one more time!!!