Background music won't play

I’m trying to set up my background music in my app but everything I’ve tried won’t work. I’ve googled a million different ways and youtubed a ton of videos. What am I missing? This is the last bit of code that i tried:

local audioisPlaying = true

local bgMusic = audio.loadstream ( “Assets/P_PURRPL.mp3” )

local function playsound()

if audioPlaying then

audio.play (bgMusic)

end

end

Runtime:addEventListener(“tap”, playSound)


and when i put it int he simulator it just says an error has occurred on lineXX near ‘,’

Is there somewhere specific that i am supposed to put this code for it to work?

This is my first app Ive done so I am very new to this.

Thanks!

Hi @b.upright,

You simply didn’t use the same variable name. You have “audioisPlaying” in one place (notice the “is” part), then you try to check “audioPlaying” in the function (no “is” there). Check your naming very carefully, and always use case-sensitive naming because Lua is case-sensitive.

Brent

Did you copy/paste the code or did you hand type it?  If you hand typed it, please copy/paste from your text editor.  Also see the <> butt in the formatting bar above?  Click that and paste your code in.

Rob

ok so i fixed that error and put it back into my main.lua file but there is still an error. Should I be putting it into my build.settings? Is there some place specific I need to insert the code?

Again I am very new to this so bare with me :stuck_out_tongue:

None of the code you posted above belongs in build.settings.  Please post your current code for us to look at?  To learn more about build.settings, please read this tutorial:  https://coronalabs.com/blog/2014/07/08/tutorial-understanding-build-settings/

Rob

Hi @b.upright,

You simply didn’t use the same variable name. You have “audioisPlaying” in one place (notice the “is” part), then you try to check “audioPlaying” in the function (no “is” there). Check your naming very carefully, and always use case-sensitive naming because Lua is case-sensitive.

Brent

Did you copy/paste the code or did you hand type it?  If you hand typed it, please copy/paste from your text editor.  Also see the <> butt in the formatting bar above?  Click that and paste your code in.

Rob

ok so i fixed that error and put it back into my main.lua file but there is still an error. Should I be putting it into my build.settings? Is there some place specific I need to insert the code?

Again I am very new to this so bare with me :stuck_out_tongue:

None of the code you posted above belongs in build.settings.  Please post your current code for us to look at?  To learn more about build.settings, please read this tutorial:  https://coronalabs.com/blog/2014/07/08/tutorial-understanding-build-settings/

Rob