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]