# How to stop a streaming sound ,when I change the scene(director)?

**URL:** <https://forums.solar2d.com/t/how-to-stop-a-streaming-sound-when-i-change-the-scene-director/304964>\
**Category:** Director Class\
**Created:** [July 18, 2012, 7:33pm UTC](https://forums.solar2d.com/t/how-to-stop-a-streaming-sound-when-i-change-the-scene-director/304964 "2012-07-18T19:33:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoolax](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/z/e5b9ba/32.png) [@zoolax](https://forums.solar2d.com/u/zoolax)\
**Post date:** [July 18, 2012, 7:33pm UTC](https://forums.solar2d.com/t/how-to-stop-a-streaming-sound-when-i-change-the-scene-director/304964/1 "2012-07-18T19:33:13Z")

</div>

Hi this is a a test for Nook,I have a button called local audio that upon press play the sound1(audio stream)  
but I have trouble figuring out how to stop the sound when I change scene using the other 3 button.  
I have tried putting audio.stop and rewind in the changeScene function and it dose not respond.  
I would appreciate if somebody know the answer to this:)

module(…,package.seeall)  
–some code  
—sound  
local sound1 = audio.loadStream(“s1.ogg”);

local playsound = function(event)

audio.play(sound1,{channel=1})

end  
–UI  
–play the A  
local audio=display.newImage(“audio.png”,\_W,\_H)  
audio:setReferencePoint(display.CenterReferencePoint)  
audio:scale(0.25,0.25)  
audio.x=\_W\*0.5+((audio.width\*0.27)/2) ;audio.y=\_H\*0.07

–some code

–for changing scene  
function changeScene(event)  
if (event.phase== “ended”) then  
director:changeScene(event.target.scene);  
end

end

–I have tried this .this dose not work–[[function changeScene:touch(event)  
if (event.phase == “began”) then  
audio.fade(sound1) – fades out soundtrack here!  
elseif (event.phase == “ended”) then  
print(“Home, ended phase”)  
timer.performWithDelay(1000, function() director:changeScene(event.target.scene) end, 1)  
end  
end]]

localGroup:insert(bg1)  
localGroup:insert(audio)  
localGroup:insert(home)  
localGroup:insert(back)  
home:addEventListener(“touch”,changeScene);  
back:addEventListener(“touch”,changeScene);  
forth:addEventListener(“touch”,changeScene);  
audio:addEventListener(“touch”,playsound)  
return localGroup;  
end  
I have figured this out,but I still like to hear your way,to see what is better:)  
thanks [import]uid: 141482 topic\_id: 28788 reply\_id: 328788[/import]

---

<div class="post-metadata">

**Author:** ![Marco\_De\_Vincenzi](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@Marco\_De\_Vincenzi](https://forums.solar2d.com/u/Marco_De_Vincenzi)\
**Post date:** [July 19, 2012, 3:17am UTC](https://forums.solar2d.com/t/how-to-stop-a-streaming-sound-when-i-change-the-scene-director/304964/2 "2012-07-19T03:17:44Z")

</div>

Insert sound1 into localGroup 🙂 [import]uid: 27760 topic\_id: 28788 reply\_id: 116004[/import]

---

<div class="post-metadata">

**Author:** ![crazypsycho6973052](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/c/8491ac/32.png) [@crazypsycho6973052](https://forums.solar2d.com/u/crazypsycho6973052)\
**Post date:** [July 19, 2012, 7:43am UTC](https://forums.solar2d.com/t/how-to-stop-a-streaming-sound-when-i-change-the-scene-director/304964/3 "2012-07-19T07:43:15Z")

</div>

This is how I have handled the music and sounds for my game.  
[lua]-- Pre-loads our sounds  
music = audio.loadStream(“LevelTwoSongFinal.mp3”) – after setting up variables

audio.play(music, {loops = -1}) ---- just before you return localGroup at the end of the code

—then when the game ends I do this

function titleScreen( event)

audio.pause(music)  
music = nil  
gameIsActive = nil  
director:changeScene(“mainmenu”)  
end

[import]uid: 49863 topic\_id: 28788 reply\_id: 116039[/import]
