Audio Question

I have 4 buttons with audio on it, when I click on buttons 1 and 2 for example my audio is playing, but audio is overlapping.
My question is how to remove audio from that second buttons for example: button 1 click audio is playing and then button 2 click audio stop on button 1 and button 2 is playing viceversa.

I have ui.lu for buttons.

Thank you [import]uid: 22037 topic_id: 17649 reply_id: 317649[/import]

Put:

return true

At the end of your touch function :slight_smile: [import]uid: 84637 topic_id: 17649 reply_id: 67219[/import]

Here is my code where I exactly should add this code ?

[lua]module(…, package.seeall)
local ui = require(“ui”)

function new()
local localGroup = display.newGroup()


local beepsound = media.newEventSound( “1.mp3” )
local button1Release = function( event )
media.playEventSound( beepsound )
display.remove( allthemgraphics ); allthemgraphics = nil
end
local beepsound = media.newEventSound( “2.mp3” )
local button2Release = function( event )
media.playEventSound( beepsound )
display.remove( allthemgraphics ); allthemgraphics = nil
end
local beepsound = media.newEventSound( “3.mp3” )
local button3Release = function( event )
media.playEventSound( beepsound )
display.remove( allthemgraphics ); allthemgraphics = nil
end
local beepsound = media.newEventSound( “4.mp3” )
local button4Release = function( event )
media.playEventSound( beepsound )
display.remove( allthemgraphics ); allthemgraphics = nil
end

local background = display.newImage (“background2.png”)
localGroup:insert(background)
–> Set the background


– 1 –

local button1 = ui.newButton{
default = “button.png”,
over = “buttonover.png”,
onRelease = button11Release,
onEvent = buttonHandler,
id = “button1”,
text = “11”,
font = “Trebuchet-BoldItalic”,
textColor = { 51, 51, 51, 255 },
size = 13,
emboss = false
}

button1.x = 82; button1.y = 48
localGroup:insert(button1)

– 2 –

local button2 = ui.newButton{
default = “button.png”,
over = “buttonover.png”,
onRelease = button2Release,
onEvent = buttonHandler,
id = “button2”,
text = “2”,
font = “Trebuchet-BoldItalic”,
textColor = { 51, 51, 51, 255 },
size = 13,
emboss = false
}

button2.x = 238; button2.y = 48
localGroup:insert(button2)


– 3 –

local button3 = ui.newButton{
default = “button.png”,
over = “buttonover.png”,
onRelease = button3Release,
onEvent = buttonHandler,
id = “button3”,
text = “3”,
font = “Trebuchet-BoldItalic”,
textColor = { 51, 51, 51, 255 },
size = 9,
emboss = false
}

button3.x = 82; button3.y = 92
localGroup:insert(button3)


– 4 –

local button4 = ui.newButton{
default = “button.png”,
over = “buttonover.png”,
onRelease = button4Release,
onEvent = buttonHandler,
id = “button4”,
text = “4”,
font = “Trebuchet-BoldItalic”,
textColor = { 51, 51, 51, 255 },
size = 8,
emboss = false
}

button4.x = 238; button22.y = 4
localGroup:insert(button22)
return localGroup
end[/lua]

Thanks Danny [import]uid: 22037 topic_id: 17649 reply_id: 67523[/import]

Ah your doing more than i realized.

i suggest using the openAl audio framework as opposed to the eventSound framework and also you probably want to stop the sound before playing the new one :slight_smile: [import]uid: 84637 topic_id: 17649 reply_id: 67746[/import]