Just a simple in game client side music player that I made which plays music from youtube. I made it for myself and guessed that I may as well see if others wanted it too. If anyone wants me to I can adapt it for online. To add a song just look at the other examples.
[lua]
YoutubeMusic = {}
MusicInfo = {}
-- URL, Name of song, length of song (seconds)
MusicInfo["http://www.youtube.com/watch?v=VuNIsY6JdUw&feature=channel"] = {"Taylor Swift - You Belong With Me", 228}
MusicInfo["http://www.youtube.com/watch?v=uelHwf8o7_U"] = {"Eminem - Love The Way You Lie ft. Rihanna", 267}
MusicInfo["http://www.youtube.com/watch?v=9ewTkrfaWtA"] = {"Katy Perry - Not Like the Movies - Official Lyric Video ", 246}
MusicInfo["http://www.youtube.com/watch?v=oRWFuCkBV2k"] = {"30 Seconds To Mars - From Yesterday (The Wish)", 323}
MusicInfo["http://www.youtube.com/watch?v=IyvvCuIHrJw"] = {"Foo Fighters - Everlong ", 289}
MusicInfo["http://www.youtube.com/watch?v=0rUVEhEt3Ng&feature=channel"] = {"Foo Fighters - Walking After You", 242}
YoutubeMusic[1] = "http://www.youtube.com/watch?v=VuNIsY6JdUw&feature=channel"
YoutubeMusic[2] = "http://www.youtube.com/watch?v=uelHwf8o7_U"
YoutubeMusic[3] = "http://www.youtube.com/watch?v=9ewTkrfaWtA"
YoutubeMusic[4] = "http://www.youtube.com/watch?v=oRWFuCkBV2k"
YoutubeMusic[5] = "http://www.youtube.com/watch?v=IyvvCuIHrJw"
YoutubeMusic[6] = "http://www.youtube.com/watch?v=0rUVEhEt3Ng&feature=channel"
FrameRadio = vgui.Create("DFrame")
FrameRadio:SetVisible(false)
YouTubeMusic = vgui.Create("HTML", FrameRadio)
function StartRadio(ply, cmd, args)
if RadioOn then ply:ChatPrint("The radio is already on!") return end
RadioOn = true
if not args[1] then
PlaySong(ply, nil, {1, nil})
else
PlaySong(ply, nil,{ args[1], nil})
end
end
concommand.Add("StartRadio", StartRadio)
function PlaySong(ply, cmd, args)
if not RadioOn then
ply:chatPrint("The radio isn't on")
end
local songID2 = tonumber(args[1])
if args[2] then local loop = true end
if not YoutubeMusic[songID2] then
ply:ChatPrint("That is an invalid song!")
RadioOn = false
return
end
YouTubeMusic:OpenURL(YoutubeMusic[songID2])
TimeStartedSong = CurTime()
CurrentSongPlayingID = songID2
ply:ChatPrint("Radio started, playing song \" " .. MusicInfo[YoutubeMusic[songID2]][1] .. "\"")
timer.Simple(MusicInfo[YoutubeMusic[songID2]][2], function()
if loop then
PlaySong(ply, nil, {CurrentSongPlayingID, 1})
else
if YoutubeMusic[CurrentSongPlayingID + 1] then
PlaySong(ply, nil, {CurrentSongPlayingID + 1, nil})
else
PlaySong(ply, nil, {1, nil})
end
end
end)
end
concommand.Add("PlaySong", PlaySong)
function StopRadio(ply)
if RadioOn then
YouTubeMusic:OpenURL("www.google.co.uk")
RadioOn = false
ply:ChatPrint("Stopped radio")
else ply:ChatPrint("The radio isn't on!")
end
end
concommand.Add("StopRadio", StopRadio)
[/lua]
Sorry, you need to Log In to post a reply to this thread.