Hesa
Hesa

Reputation: 7

how to play a sound on a button click, only once in corona sdk?

im trying to paly a sound only once when user clicks on the button how can i do that?

here is what i have done so far, but how can i add the sound:

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
}

Upvotes: 0

Views: 956

Answers (1)

Jack
Jack

Reputation: 60

I don't know if it's what you need for your programm, but try to include the audio lib and use

local laserSound = audio.loadSound( "laserBlast.wav" ) //init the sound 
local laserChannel = audio.play( laserSound )  //play the sound once complete

Upvotes: 1

Related Questions