Corona SDK 中不需要的音频延迟

Unwanted audio delay in Corona SDK

我目前正在制作一个非常简单的应用程序,当点击图像时,会播放声音并且一些文本会记录点击次数。但是,我注意到音频有一些明显的延迟,在单击图像后需要半秒钟才能播放声音。有人知道为什么会这样吗?

local function btnTouch(event)
    if event.phase == "began" then
    media.playSound( "btnSnd.mp3" )
    score = score + 1
    btnText.text = score
    return true
    end
end

--code
imageBtn:addEventListener("touch", btnTouch)

答案很可能是需要加载声音。尝试将其切换为音频并预加载。试试看这是否给您想要的结果:

local buttonSendAudio = audio.loadSound( "btnSnd.mp3")
local function btnTouch(event)
    if event.phase == "began" then
        audio.play( buttonSendAudio )
        score = score + 1
        btnText.text = score
        return true
    end
end

--code
imageBtn:addEventListener("touch", btnTouch)

https://docs.coronalabs.com/daily/guide/media/audioSystem/index.html

值得检查一下声音是否在 mp3 中存储了一些静音。 使用任何音频编辑器打开它,查看声音的波形。