如何在Corona SDK中仅在按下按钮时播放声音一次?

我想在用户点击按钮时只播放一次声音,我该怎么做?

到目前为止,我已经完成了以下内容,但我如何添加声音:

local widget = require( "widget" )
--button performed only once
local minusButtonPressed = false

local function handleButtonEvent( event )

    if ( ( "ended" == event.phase ) and (minusButtonPressed == false) and (afterCorrect == false)) then
        minusScore()
        print( "Button was pressed and released" )
        --disable the button
        minusButtonPressed = true
    end
 end

local button1 = widget.newButton
{
    width = 350,
    height = 360,
    left= 30,
    top= 220,
    defaultFile = "speakers.png",
    overFile = "wrong.png",
    --label = "button",
    onEvent = handleButtonEvent
}
点赞
用户3307771
用户3307771

我不知道这是否是您程序需要的,但请尝试包含音频库并使用以下代码

local laserSound = audio.loadSound( "laserBlast.wav" ) //初始化声音
local laserChannel = audio.play( laserSound )  //播放声音,播放完成后仅播放一次
2014-06-02 11:07:38