Audio help

Hello. I’m new to this and I’ve just been working on a simple app to teach myself and learn. Right now I’m stuck on an audio issue.

I only have one channel for the audio and it’s all the noise coming out of the app. What I want to do is make it FADE to a pause on the press of a button. I want it to resume on the press of the same button. I know how to make the button and I have it made.

I’ve loaded the stream using audio.loadStream.

Is this enough info? Thanks.

Nathan [import]uid: 39302 topic_id: 18774 reply_id: 318774[/import]

You can do something like this here. I’m not sure that fade has a listener that you can use to pause the music when the fade ends so I set a timer for 1 second also, so around the time it stops fading it pauses the music.

Then basically there’s a switch (musicToggle) that will decide if the music is playing or not and when it’s not it resumes the music and sets the volume back to 1.

I haven’t tested the code, so I’m not sure it works but it should be enough to understand the idea.

[code]

local musicToggle = true

local musicTrack = audio.loadStream(“whatever.mp3”)
local musicChannel = audio.play(musicTrack,{ channel=1 })

local function pauseMusic()
audio.pause(musicChannel)
end

local function toggleMusic(e)
if(e.phase == “ended”) then
if(musicToggle) then
audio.fade({ channel = musicChannel, time = 1000, volume = 0 })
timer.performWithDelay(1000,pauseMusic,1)
else
audio.setVolume(1,{ channel = musicChannel })
audio.resume(musicChannel)
end
musicToggle = not musicToggle
end
end

local button = display.newRect(0,0,50,50)
button.x = 100
button.y = 100
button:addEventListener(“touch”,toggleMusic)

[/code] [import]uid: 61899 topic_id: 18774 reply_id: 72530[/import]