Sound.PlayURL - How to stop it?

Hello,

I’ve got a radio stream playing through sound.PlayURL but I’m having trouble stopping it from playing whilst it’s already started.

Use the callback function to set it to something that can be accessed outside the function itself. Then call :Stop()

Could you show me how the callback function works? After playing around I’ve been unsuccessful.

Clientside Code


local Music
function startMusic(URL)
   if Music:IsValid() then
      Music:Stop()
   end
   sound.PlayURL(URL,"play",function(chan) Music = chan end)
end

function stopMusic()
   if Music:IsValid() then
      Music:Stop()
   end
end

If you want a more complex look at how it can work, view this thread: http://forum.facepunch.com/showthread.php?t=1282825