media.playSound including loop and timer ?

Hi,

i have a problem making this function with media.playsound

I have a sound that will be played when a button is pressed.
If you press the button twice, the sound stops.

But in the function it self i need also the looped playing and a timer that stops after an defined time.

I tried it with the loop, but when it loops the first time , te app crashes. The Problem is that i need a time longer than the soundfile.

Without the loop and with the timerfunction it works fine.

Any ideas on this ?

[lua]local beachbutton = display.newImage( “beach.png” )

beachbutton.x = display.contentWidth / 3.3
beachbutton.y = display.contentHeight /3.8

local soundPlaying = false – set flag

function beachbutton:tap( event )

if not soundPlaying then

media.playSound( “oceanwave.mp3”, {loops = -1} )

else

media.stopSound()

end

soundPlaying = not soundPlaying – flip flag

end

beachbutton:addEventListener( “tap”, beachbutton )[/lua]

Thanks [import]uid: 37574 topic_id: 7713 reply_id: 307713[/import]