HELP PLS PLS HELP how do you stop music??
im making a kinda spotify app kinda thing and that you cant stop music is soooooooooooo anoying :( pls help
im making a kinda spotify app kinda thing and that you cant stop music is soooooooooooo anoying :( pls help
wait i found a way but its anoying now i need to stop every music on every music thing init = function() ct.init()
at = 0 end
update = function()
if keyboard.press.UP then at += 25 end
if keyboard.press.DOWN then at -= 25 end
// music play if keyboard.press.P and at == 0 then school.stop() phonk = audio.playMusic("phonk", 1)
elsif keyboard.press.P and at == 25 then phonk.stop() school = audio.playMusic("school", 1) end
ct.camera.glideTo(0, at, zoom=1)
print(at) end
draw = function() screen.clear("gray") ct.fillRect(0, at, 100, 25, "white") music1 = ct.drawText("phonk", 0, 0, 30, "black") end
Maybe you can create all your music objects at the start and have them stop immediately?
name_list = ["school", "phonk"]
controller_list = []
current_song = 0
for n in name_list
  local c = audio.playMusic( n, 1 )
  c.stop()
  controller_list.push(c)
end
controller_list[current_song].play()
Then when you update current_song to the index of the song you want, you can call stop on the music that is playing. Or maybe a bit easier, you can iterate through the controller_list and just stop all of them before you start the one you want.
// current_song's value just changed...
for c in controller_list
  c.stop()
  c.setPosition(0)
end
controller_list[current_song].play()
I use this simple music manager:
game_music = object
  enabled = true
  
  handle = 0
  name = ""
  
  loop = function(name)
    if not enabled then return end
    
    if this.name == name then
      return
    end
    
    stop()
    
    playing = true
    handle = audio.playMusic(name, 1, loop)
    handle.setPosition(0)
    this.name = name
  end
  
  pause = function()
    if handle then
      handle.stop()
    end
  end
  
  stop = function()
    pause()
    handle = 0
    name = ""
  end
  
  update = function()
    if handle then
      handle.play()
      if not enabled then
        stop()
      end
    end
  end
end
thank!!!