我对Corona游戏开发完全陌生,如果这对我的功能有所帮助,我会坚持在游戏中添加播放/停止按钮用来播放背景音乐:
local backgroundMusicChannel
local backgroundMusicSounds = {}
if (backgroundMusic == true) then
for i=1, backgroundMusicNumber do
backgroundMusicSounds["bg" .. i] = audio.loadStream("sounds/bg" .. i ..".mp3")
end
end
function playBackgroundMusic()
if (backgroundMusic == true) then
backgroundMusicChannel = audio.play( backgroundMusicSounds["bg" .. math.random(1,backgroundMusicNumber)], { channel=5, loops=-1 } )
end
end
function stopBackgroundMusic()
if (backgroundMusic == true) then
audio.stop( backgroundMusicChannel )
end
end
答案 0 :(得分:0)
--Load audio stream
local backgroundMusic = audio.loadStream( "backgroundMusic.m4a" )
--Play the background music on channel 1, loop infinitely
local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1} )
--Pause Audio Stream
local backgroundMusicChannel = audio.play( backgroundMusic, { loops=-1 } )
audio.pause( backgroundMusicChannel )
--Resume after 3 seconds
timer.performWithDelay( 3000, function()
audio.resume( backgroundMusicChannel )
end, 1 )