Start Stop Sound at the same Button

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: 7505 reply_id: 307505[/import]

Two solutions from the top of my head without actually testing anything:

local isPlaying = false  
--inside your function  
if (isPlaying == true) then  
 isPlaying = false  
 --logic to stop playing  
else  
 isPlaying = true  
 --logic to start playing  
end  
  

OR you could place two buttons at the same position, but hide the one that was just pressed and show the other. [import]uid: 13180 topic_id: 7505 reply_id: 26622[/import]