audio.stop() not stopping my audio when placed within scene:exitScene( event ) function

I have four scenes in my application. In the first I simply display a welcome screen with the game name and tap anywhere to continue message. This all works fine as I set the event listener in the enterScene function and un-set it in the exitScene function.

The problem is with the audio I play on that screen. in createScene I set a local var to the audio.loadSound and then do audio.play in the enter scene fucntion. This works fine and the audio plays. However, when I tap the screen and change scenes the audio continues to play in this new scene. This suggests that either exitScene isn’t being called or audio.stop() is being ignored (or just plain doesn’t work)

I’ve included my code below for the offending scene if anyone would like to tell me what I’m doing wrong as I can’t see anything obvious.

[code]
module( …, package.seeall )

local scene = storyboard.newScene()
local background
local intro

local function jacksOrbetterGame( event )

if event.phase == “ended” then
storyboard.gotoScene( “jacksOrBetter” )
return true
end
end

function scene:createScene( event )
local loaclGroup = self.view

background = display.newImage(“title.png”)
intro = audio.loadSoubd(“title.mp3”)

localGroup:insert( background )
end

function scene:enterScene( event )
storyboard.purgeScene(“stats”)
background:addEventListener(“touch”, jacksOrbetterGame )

audio.play( intro )
end

function scene:exitScene( event )
background:removeEventListener( “touch”, background )
audio.stop()
end

function scene:destroyScene( event )
end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene
[/code] [import]uid: 82631 topic_id: 22838 reply_id: 322838[/import]

It is, you have to pass the handle to the channel you want to stop.

This should work :

[code]
module( …, package.seeall )

local scene = storyboard.newScene()
local background
local intro, introHandle

local function jacksOrbetterGame( event )

if event.phase == “ended” then
storyboard.gotoScene( “jacksOrBetter” )
return true
end
end

function scene:createScene( event )
local loaclGroup = self.view

background = display.newImage(“title.png”)
intro = audio.loadSoubd(“title.mp3”)

localGroup:insert( background )
end

function scene:enterScene( event )
storyboard.purgeScene(“stats”)
background:addEventListener(“touch”, jacksOrbetterGame )

introHandle = audio.play( intro )
end

function scene:exitScene( event )
background:removeEventListener( “touch”, background )
audio.stop(introHandle)
end

function scene:destroyScene( event )
end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)

return scene [import]uid: 84637 topic_id: 22838 reply_id: 91258[/import]

Your right it is supposed to, let me know if that fixes it.

If it does then we will investigate further [import]uid: 84637 topic_id: 22838 reply_id: 91272[/import]

Ah ok I’ll give that a go but, I thought audio.stop() with no parameters was supposed to stop all playing channels.

Is that just not working then?

Update:

Ok it appears that audio.stop( handle ) works when placed in exitScene but, audio.stop() doesn’t.

I think this is a bug with the storyboard events as the same audio.stop() call works when placed in a function of an already running scene. This suggests that audio.stop() somehow doesn’t complete successfully when used in exitScene.
[import]uid: 82631 topic_id: 22838 reply_id: 91271[/import]

Ok great.

Can you file a bug for that please?

http://bugs.anscamobile.com

Please include a working example test case with all needed assets in order to test it.

Thanks! [import]uid: 84637 topic_id: 22838 reply_id: 91276[/import]