audio.- playing button

At moment for sound playing button I am using code outlined below;
could anyone help me with making the button that works exactly the same but is based on audio.* instead of outdated media.*? Tried to do this, but my coding skills are somewhat still weak
Thanks

[lua]local widget = require(“widget”)

local BEEP = media.newEventSound(“BEEP.mp3”)

local button_BEEP_Press = function(event)
media.playEventSound(BEEP,button_BEEP_Press)
end

local button_BEEP = widget.newButton
{
defaultFile = “buttondefault.png”,
overFile = “buttonpressed.png”,
onPress = button_BEEP_Press,
}
button_BEEP.x = display.contentCenterX; button_BEEP.y = display.contentCenterY[/lua]
 

^^^^^

Change media.newEventSound(“BEEP.mp3”) to audio.loadSound(“BEEP.mp3”)

Change media.playEventSound(BEEP, button_BEEP_Press) to audio.play(BEEP)

Rob

Ok it works now well but I have one problem more. As I click this button (it plays) and hold on the cursor as a clicked, then move out of button area and go on the button again with this cursor I have been holding clicked since the first button click, it does not play but only shows the overFile. And when I click on background area and drive the click-holding cursor over button, button does nothing.

My point is having ability to do smooth slides between buttons (without neccesity of getting your finger in the air to make next button play etc.) Thanks for help
 

You probably want to be using onEvent instead of onPress. That way you can look for other touch events, like “moved”, “ended” and “cancelled”.  The onPressed event basically only responds to a “began” events and when you drag your finger from one button to another, you may not get a “began” event since you didn’t being a new touch. 

Rob

Well it all seems to be working. Besides sound which glitches terribly after adding onEvent. If nothing more is possible to do in order to fix that - never mind.

^^^^^

Change media.newEventSound(“BEEP.mp3”) to audio.loadSound(“BEEP.mp3”)

Change media.playEventSound(BEEP, button_BEEP_Press) to audio.play(BEEP)

Rob

Ok it works now well but I have one problem more. As I click this button (it plays) and hold on the cursor as a clicked, then move out of button area and go on the button again with this cursor I have been holding clicked since the first button click, it does not play but only shows the overFile. And when I click on background area and drive the click-holding cursor over button, button does nothing.

My point is having ability to do smooth slides between buttons (without neccesity of getting your finger in the air to make next button play etc.) Thanks for help
 

You probably want to be using onEvent instead of onPress. That way you can look for other touch events, like “moved”, “ended” and “cancelled”.  The onPressed event basically only responds to a “began” events and when you drag your finger from one button to another, you may not get a “began” event since you didn’t being a new touch. 

Rob

Well it all seems to be working. Besides sound which glitches terribly after adding onEvent. If nothing more is possible to do in order to fix that - never mind.