I am have an app that plays one song in a scene . How do I change it so that multiple songs can be randomly chosen from to play ? This is what I have so far :
game.lua
local song1 = audio.loadSound( "sounds/Death Song.mp3" ) local song2 = audio.loadSound( "sounds/stay.mp3" ) local song3 = audio.loadSound( "sounds/menu\_music.mp3" ) local song = {song1, song2, song3} local playRandom playRandom = function () if( #song == 0 ) then return end local aleatorio= math.random(1,#song) audio.play (song[aleatorio], { onComplete = playRandom } ) table.remove ( song, aleatorio ) end playRandom() function scene:show(event) if event.phase == 'did' then eachframe.add(self) -- Each frame self:eachFrame() is called -- Only check once in a while for level end self.endLevelCheckTimer = timer.performWithDelay(2000, function() self:endLevelCheck() end, 0) -- Show help image once if not databox.isHelpShown then timer.performWithDelay(2500, function() self.sidebar:show() self:setIsPaused(true) end) end sounds.playStream( playRandom ) end end
When i use this code the songs all override each other and the song from the menu plays also . Can someone help me ?