dl1606
1
Hi,
i’m new to corona, so i’m sorry for this question, because i cant figure it out.
I have a Button in the app that plays a looped sound and with another tap on the button the sound should stop.
Here’s the Code
[lua]local button = display.newImage( “birds_button3.png” )
button.x = display.contentWidth / 2
button.y = display.contentHeight /2
function button:tap( event )
media.playSound( “byriver.mp3” )
end
button:addEventListener( “tap”, button )[/lua]
Has anyone an idea ?
Thanks
[import]uid: 37574 topic_id: 7508 reply_id: 307508[/import]
evs
2
You could use a boolean flag:-
[code]
local button = display.newImage( “birds_button3.png” )
button.x = display.contentWidth / 2
button.y = display.contentHeight /2
local soundPlaying = false – set flag
function button:tap( event )
if not soundPlaying then
media.playSound( “byriver.mp3” )
else
media.stopSound()
end
soundPlaying = not soundPlaying – flip flag
end
button:addEventListener( “tap”, button )
[/code] [import]uid: 8366 topic_id: 7508 reply_id: 26649[/import]
dl1606
3
Hi again,
Thank you for your answer.
I have tried it and it works. I tried it with more than one Button and it’s working too.
Is it possible to play 2 Sounds at the same time or is this a potential memory problem ?
Thanks to all
[import]uid: 37574 topic_id: 7508 reply_id: 26773[/import]