I am having an issue when calling audio.dispose() to clear some memory. Basically, I create an audio with my background music in it, call it immediately to start playing, and then want to dispose of it when I change scenes. (I am using Director BTW) Everything worked fine with the below code except when i add in audio.dispose(bg_music); I get a crash. Heres what I’m working with.
[lua]local bg_music = audio.loadStream(“sounds/background.wav”)
audio.play(bg_music);
–Body of code here doing stuff while bg_music plays
–…
–…
local function changeScene(e)
audio.stop(bg_music);
audio.dispose(bg_music);
if(e.phase == “ended” or e.phase == “cancelled”) then
director:changeScene(e.target.scene);
end
end
buttonToChangeScene:addEventListener(“touch”, changeScene);[/lua]
If “audio.dispose(bg_music);” is commented out, the code works fine. I should also mention I use the same background music for each level so when the scene is changed I would like the bg_music to stop, then be unloaded. This was I can load it again in the next level and not have multiple copies using memory. (I know thats not the best way to explain it but its getting late haha) Thanks again in advance, I could’t even imagine being this far into my app development without this forums help!
[import]uid: 50511 topic_id: 25857 reply_id: 325857[/import]
[import]uid: 52491 topic_id: 25857 reply_id: 104610[/import]