I’m facing a really weird issue… Sometimes when my code calls audio.play, no sound is played. BUT only sometimes… Seems like 80% of the time it works as expected, but every once in a while there is just no sound…
I have a function playBackgroundMusic which I call at the start of the game to play the background music… see below:
However, every once in a while no sound is played. It seems to happen more often upon the first launch of the game, but not consistently. Maybe 2 out of 10 times there is no sound, and the other 8 times it will work just fine.
In my destroy when I change scenes, I call disposeBackgroundMusic() which is also below.
I also do an audio.stop with a pairs loop to dispose of other sound effects that are unrelated to the background music.
What I don’t understand is why it works most of the time, but occasionally I get no sound. Does anyone see any issues?
local function playBackgroundMusic() local randomSong = math.random(1,6) if(randomSong == 1) then print("playing aurea...") backgroundMusic = audio.loadStream("sounds/aurea.mp3") audio.play( backgroundMusic, { channel=1, loops=-1 } ) elseif(randomSong == 2) then print("playing carefree...") backgroundMusic = audio.loadStream("sounds/carefree.mp3") audio.play( backgroundMusic, { channel=1, loops=-1 } ) elseif(randomSong == 3) then print("playing fretless...") backgroundMusic = audio.loadStream("sounds/fretless.mp3") audio.play( backgroundMusic, { channel=1, loops=-1 } ) elseif(randomSong == 4) then print("playing rainbows...") backgroundMusic = audio.loadStream("sounds/rainbows.mp3") audio.play( backgroundMusic, { channel=1, loops=-1 } ) elseif(randomSong == 5) then print("playing upbeat...") backgroundMusic = audio.loadStream("sounds/upbeat.mp3") audio.play( backgroundMusic, { channel=1, loops=-1 } ) elseif(randomSong == 6) then print("playing wallpaper...") backgroundMusic = audio.loadStream("sounds/wallpaper.mp3") audio.play( backgroundMusic, { channel=1, loops=-1 } ) end end
local function disposeBackgroundMusic() audio.stop(1) audio.dispose(backgroundMusic) backgroundMusic = nil end