How can I make the audio stop playing when going to another scene?

I have this line of code at the top of my code

local endingMusic = audio.loadSound( “endingMusic.mp3”) – Just to load the song mp3

then in the enterScene I have this line

audio.play(endingMusic) – So the song stars to play very nice.

But when I go to another scene

local function buttonHome()
        storyboard.gotoScene( “home”, “crossFade”, 1000 )    
    return true
end
 

The music keeps playing…

How can I stop the music when I’m going to another scene?

Thanks for your help.

Victor

you need to get the channel number of the sound you are playing and then call the audio.stop() API call on that channel.

Thank you Rob.

That works!, I was puttin

audio.remove  (  )

but is

audio.stop  (  )

and it was on channel one, so I just did this on the exitScene

audio.stop ( 1 )

And it works!

Thanks.

you need to get the channel number of the sound you are playing and then call the audio.stop() API call on that channel.

Thank you Rob.

That works!, I was puttin

audio.remove  (  )

but is

audio.stop  (  )

and it was on channel one, so I just did this on the exitScene

audio.stop ( 1 )

And it works!

Thanks.

Actually, I’m also want to make the audio stop playing when going to another scene

I’m using the storyboard to make the scene going to another scene

But, how to get the channel number - how can I know the sound is playing on which channel number?

Pls help, thank

Also, how to set the certain channel let say channel 1 for the bg music, channel 2 for narrator speech…

thank

Hi shirleylww.

I don’t know that answer.

But I will use the logic. Put just 1 audio file, and put audio.stop ( 1 ) if it stops it’s in audio 1

if not then put audio.stop ( 2 ), the audio.stop ( 3 ), and so on. Until you find the channel number, that’s what I’m doing.

Unless someone else see this and they can tell us a better way. I’m sure there should be a way to setting the channel numbers

I think there is one line of code

  audio.totalChannels

but I don’t know how to use this.

I wish I could help you more

Victor

Actually, I’m also want to make the audio stop playing when going to another scene

I’m using the storyboard to make the scene going to another scene

But, how to get the channel number - how can I know the sound is playing on which channel number?

Pls help, thank

Also, how to set the certain channel let say channel 1 for the bg music, channel 2 for narrator speech…

thank

Hi shirleylww.

I don’t know that answer.

But I will use the logic. Put just 1 audio file, and put audio.stop ( 1 ) if it stops it’s in audio 1

if not then put audio.stop ( 2 ), the audio.stop ( 3 ), and so on. Until you find the channel number, that’s what I’m doing.

Unless someone else see this and they can tell us a better way. I’m sure there should be a way to setting the channel numbers

I think there is one line of code

  audio.totalChannels

but I don’t know how to use this.

I wish I could help you more

Victor

on programming  – Music = audio.play( Music,{ channel=1, loops=-1, fadein=50 } ) //u have to decalre channel no while playing audio. so to stop audio its simple      –  audio.stop(channel no.) 

on programming  – Music = audio.play( Music,{ channel=1, loops=-1, fadein=50 } ) //u have to decalre channel no while playing audio. so to stop audio its simple      –  audio.stop(channel no.) 

great post it helped, i have a song i set the channel and was able to stop the music when going to another scene but when i return to the same scene the song or any other sound effects wont play anymore how do i fix this?

Hi @JoelG411,

Please watch this video tutorial on what happens (internally) when you reload scenes:

http://www.youtube.com/embed/2IDzu6qWRCM?rel=0

And read this tutorial on handling cross-scene audio:

http://www.coronalabs.com/blog/2013/06/04/tutorial-handling-cross-scene-audio/

Hope these help,

Brent

will do thanks

great post it helped, i have a song i set the channel and was able to stop the music when going to another scene but when i return to the same scene the song or any other sound effects wont play anymore how do i fix this?

Hi @JoelG411,

Please watch this video tutorial on what happens (internally) when you reload scenes:

http://www.youtube.com/embed/2IDzu6qWRCM?rel=0

And read this tutorial on handling cross-scene audio:

http://www.coronalabs.com/blog/2013/06/04/tutorial-handling-cross-scene-audio/

Hope these help,

Brent

will do thanks

Thanks all.

Rob, you are such a great man!