How to Make Background music stop With click event

Hello 

I got my music to work when the menu loads up and my click sound to play when I click the button.

How do I get the Background music to stop when I click the start button?

I used audio.stop()

But it just doesnt work the music keeps playing…

Does Corona not support that function???

Heres My Code

local composer = require("composer") local scene = composer.newScene() local widget = require "widget" widget.setTheme("widget\_theme\_android\_holo\_dark") -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- local forward references should go here local Button\_Start local Button\_Settings -- for saving user data (I really dont need this) user = loadsave.loadTable("user.json") -- for starting the game local function onPlayTouch(event) if (event.phase == "ended") then audio.play(\_CLICK) audio.stop(\_BACKGROUNDMUSIC) composer.gotoScene("scene\_game", "slideLeft") end end -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create(event) audio.play(\_BACKGROUNDMUSIC) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen -- Code here runs when the scene is first created but has not yet appeared on screen local background = display.newImageRect(sceneGroup, "images/menuscreen/carbonBg.png", 620, 780) background.x = \_CX; background.y = \_CY; local gameTitle1 = display.newImageRect(sceneGroup, "images/menuscreen/TapTxt.png", 300, 200) gameTitle1.x = \_L; gameTitle1.y = \_CH \* 0.2 local gameTitle2 = display.newImageRect(sceneGroup, "images/menuscreen/creator.png", 90, 250) gameTitle2.x = \_R - gameTitle2.width; gameTitle2.y = \_CH \* 0.3 -- Create some buttons --start button Button\_Start = widget.newButton{ width = 300, height = 200, defaultFile = "images/menuscreen/startBtn.png", --overFile = "images/menuscreen/settingsBtn.png", onEvent = onPlayTouch } Button\_Start.x = \_L + 150 Button\_Start.y = \_B - 150 sceneGroup:insert(Button\_Start) --settings button Button\_Start = widget.newButton{ width = 300, height = 200, defaultFile = "images/menuscreen/settingsBtn.png", --overFile = "images/menuscreen/settingsBtn.png", onEvent = onPlayTouch } Button\_Start.x = \_L + 350 Button\_Start.y = \_B - 150 sceneGroup:insert(Button\_Start) --Transitions moveA8 = transition.to(gameTitle1, {x = 250, delay = 250}) moveA9 = transition.to(gameTitle2, {x = 250, delay = 250}) end -- show() function scene:show(event) local sceneGroup = self.view local phase = event.phase if (phase == "will") then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif (phase == "did") then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide(event) local sceneGroup = self.view local phase = event.phase if (phase == "will") then -- Code here runs when the scene is on screen (but is about to go off screen) elseif (phase == "did") then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy(event) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) -- ----------------------------------------------------------------------------------- return scene

In audio.play() you play the audio handle, not the channel. You need to do something like this:

local channelMusic = audio.play(handleName)

and then:

audio.stop(channelMusic)

Here for more:

https://docs.coronalabs.com/api/library/audio/play.html

https://docs.coronalabs.com/api/library/audio/stop.html

thanks @bgmadclown

In audio.play() you play the audio handle, not the channel. You need to do something like this:

local channelMusic = audio.play(handleName)

and then:

audio.stop(channelMusic)

Here for more:

https://docs.coronalabs.com/api/library/audio/play.html

https://docs.coronalabs.com/api/library/audio/stop.html

thanks @bgmadclown