how does audio.stop work?

Hello,

How does audio.stop() work/when does it get triggered?

When I switch scenes to the “victory” scene I call audio.stop() with no channel number to stop all audio that is playing.

But, when I answer all the question by rapidly tapping like an idiot on all the buttons, the audio does not stop when the switch is made. So I hear the two pieces of audio at the same time.

I tried also calling an audio.stop() before starting the other piece of audio but that doesn’t help.

It seems like Corona can’t handle the rapid input. 

My app is aimed at toddlers so I can’t just assume they will use the app without rapidly tapping the screen.

I had to solve it using an inbetween step. But I thought the audio.stop() would just stop the audio.

the audio does not stop when the switch is made. So I hear the two pieces of audio at the same time.

What switch? :slight_smile:

Can you explain what happens in a bit more detail (ex what happens when they tap a button?)

The switch I mean is from scene to scene.

what happens when they touch a button:

[lua]

local someAudio=audio.loadSound(“theFile”)

local function TheButton(event)

if event.phase==“ended” then

          local aFreeChannel=audio.findFreeChannel()

                    audio.play(someAudio)

           return true

      end

end

[/lua]

so nothing really special.

in the victory condition:

[lua]

 if i==resetVar then

            audio.stop()

            storyboard.gotoScene( “theScene”)

        else

–rest of the code

[/lua]

This works under normal behaviour. But I cannot force the user to behave “normally”

But if the answer buttons are pressed to quickly in succesion it somehow misses the audio.stop()

I tried a few different things. In the exit scene I also placed an audio.stop().

And I tried to put an audio.stop() in the enterScene of the new scene that gets loaded.

It doesn’t seem to stop the previous audio. 

This is all in the case when a lot of audio is being forced into the app at once. A lot I mean max 6 channels. All loaded by loadSound.

I had all the audio preloaded so I could just use audio.play to play the file. I use the same files a few times in the scene so reloading everytime I needed them seemed cumbersome.

But in the end that is what I had to do. I called an audio.dispose after every play. And reloaded the file from scratch. This seems to have solved it.

Are you using widget buttons?

In any case, your return behavior should look like this:

local myFunction( event )     local phase = event.phase       if "began" == phase then         -- do something     end       return true end

No widgets at all.

Still same behavior.

Corona seems to be overloaded with info. 

I just solved it by removing the touch listener while it is playing.

But the audio.stop should still stop the audio when it is being called. Especially when a scene is exited or entered.

the audio does not stop when the switch is made. So I hear the two pieces of audio at the same time.

What switch? :slight_smile:

Can you explain what happens in a bit more detail (ex what happens when they tap a button?)

The switch I mean is from scene to scene.

what happens when they touch a button:

[lua]

local someAudio=audio.loadSound(“theFile”)

local function TheButton(event)

if event.phase==“ended” then

          local aFreeChannel=audio.findFreeChannel()

                    audio.play(someAudio)

           return true

      end

end

[/lua]

so nothing really special.

in the victory condition:

[lua]

 if i==resetVar then

            audio.stop()

            storyboard.gotoScene( “theScene”)

        else

–rest of the code

[/lua]

This works under normal behaviour. But I cannot force the user to behave “normally”

But if the answer buttons are pressed to quickly in succesion it somehow misses the audio.stop()

I tried a few different things. In the exit scene I also placed an audio.stop().

And I tried to put an audio.stop() in the enterScene of the new scene that gets loaded.

It doesn’t seem to stop the previous audio. 

This is all in the case when a lot of audio is being forced into the app at once. A lot I mean max 6 channels. All loaded by loadSound.

I had all the audio preloaded so I could just use audio.play to play the file. I use the same files a few times in the scene so reloading everytime I needed them seemed cumbersome.

But in the end that is what I had to do. I called an audio.dispose after every play. And reloaded the file from scratch. This seems to have solved it.

Are you using widget buttons?

In any case, your return behavior should look like this:

local myFunction( event )     local phase = event.phase       if "began" == phase then         -- do something     end       return true end

No widgets at all.

Still same behavior.

Corona seems to be overloaded with info. 

I just solved it by removing the touch listener while it is playing.

But the audio.stop should still stop the audio when it is being called. Especially when a scene is exited or entered.