user2079064
user2079064

Reputation: 9

corona game SDK backgroundMusicChannel

i am trying play different background sounds on distinct .lua files. any .lua works stand alone but when I navigate between them in program not works properly. at beginning of any .lua file:

local backgroundMusic = audio.loadStream("bg3.mp3")
local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1, fadein=5000 }  ) 

and before go to other scene:

audio.pause( backgroundMusicChannel )

what I have to do !?

Upvotes: 0

Views: 945

Answers (4)

Vijai
Vijai

Reputation: 63

I use this code for stop the audio in the clean function.

local sound = audio.isChannelPlaying( backgroundMusicChannel ) if sound then audio.stop(backgroundMusicChannel) audio.dispose(backgroundMusicChannel) end

You should use this in your clean function and when you navigate another scene you must call that clean function.

Upvotes: 0

Malar
Malar

Reputation: 267

I don't the know problem exactly but try like this:

audio.stop(backgroundMusicChannel)

or

audo.dispose(backgroundMusicChannel)

Upvotes: 3

Doğancan Arabacı
Doğancan Arabacı

Reputation: 3982

Audio library uses 30 different channels to play streams. When you call play funciton, normally it looks for a free channel and assign new stream to that channel. But here you are pausing a channel which means, specified channel is still active. So basically you should remove channel = 1 from your arguments. You shouldn't use channel property at all. Or you should handle this channel assignments very carefully. Or also you can use audio.stop function which clears the channel.

Upvotes: 0

Pontus
Pontus

Reputation: 776

It looks like you are storing a reference to your backgroundMusicChannel in a local variable. Have to made sure that backgroundMusicChannel is available in the section where you call audio.pause(backgroundMusicChannel)?

Upvotes: 1

Related Questions