-- Setup conVar if GetConVar("cl_webradio") == nil then CreateClientConVar("cl_webradio", "1", true, true) CreateClientConVar("cl_webradio_volume", "1", true, true) CreateClientConVar("cl_webradio_url", "https://radio.plaza.one/mp3", true, true) end local indexPos = 0 -- Create sound object local url = GetConVar("cl_webradio_url"):GetString() local g_station = nil local g_StreamTitle = nil sound.PlayURL( url, "noplay", function(station) if (IsValid(station)) then if GetConVar("cl_webradio") ~= nil then if GetConVar("cl_webradio"):GetBool() then station:SetVolume(GetConVar("cl_webradio_volume"):GetFloat()) -- get and set the preferred volume station:Play() -- from here is where we play the sound end end g_station = station -- cached for further interaction g_StreamTitle = string.gsub(g_station:GetTagsMeta(),"StreamTitle=","") end end ) -- Control functions function play_music() if(IsValid(g_station))then g_station:Play() end end concommand.Add("play_music", play_music) function stop_music() if(IsValid(g_station))then g_station:Pause() end end concommand.Add("stop_music", stop_music) -- Handle callback behaviour cvars.AddChangeCallback( "cl_webradio", function(convar, value_old, value_new) if value_new == "0" then stop_music() else play_music() end end ) cvars.AddChangeCallback( "cl_webradio_volume", function(convar, value_old, value_new) if(IsValid(g_station))then g_station:SetVolume(value_new); end end ) cvars.AddChangeCallback( "cl_webradio_url", function(convar, value_old, value_new) if(IsValid(g_station))then g_station:Pause() sound.PlayURL( value_new, "noplay", function(station) if (IsValid(station)) then if GetConVar("cl_webradio") ~= nil then if GetConVar("cl_webradio"):GetBool() then station:SetVolume(GetConVar("cl_webradio_volume"):GetFloat()) -- get and set the preferred volume station:Play() -- from here is where we play the sound end end g_station = station -- cached for further interaction end end ) end end ) local window function show_settings() if(ispanel(window)) then window:Remove() end window = vgui.Create("DFrame") window.opacity=255;window.pinned=false; window:SetSize(420) window:Center() window:SetTitle("gm_WebRadioClient");window:SetIcon("icon16/world_go.png") window:SetVisible(true) window:SetDraggable(true) window:ShowCloseButton(false) window:MakePopup() window:SetWrap(true) hook.Add( "Think", "UpdateStreamTitle", function() if ispanel(window) && GetConVar("cl_webradio") ~= nil then np:SetText("⏸ Playback paused!");np:SizeToContents() if GetConVar("cl_webradio"):GetBool() then g_StreamTitle = string.gsub(g_station:GetTagsMeta(),"StreamTitle=","") np:SetText("⏵ Now playing: "..g_StreamTitle);np:SizeToContents() np:SetTooltip(g_StreamTitle) end end end ) window.OnClose = function() hook.Remove("Think","UpdateStreamTitle");hook.Remove("OnContextMenuOpen","aaaaaa");hook.Remove("OnContextMenuClose","aaaaaa")end window.Paint = function(self, w, h) draw.RoundedBox(0, 0, 0, w, h, Color(32, 32, 42, self.opacity)) end window:DockMargin(8,8,8,8) window:SetPaintShadow(true) np = vgui.Create("DLabel", window) -- Creates our label np:Dock(TOP);np:DockMargin(0,0,8,8) np:SetText("⏸ Playback paused!");np:SizeToContents() np:SetMouseInputEnabled(true) np.DoDoubleClick = function(self) SetClipboardText(g_StreamTitle) end field = vgui.Create("DPanel",window) field:Dock(TOP);field:SetBackgroundColor(Color(22,22,32,window.opacity/2)) url = vgui.Create("DTextEntry",field) --url.History = {} urls = { "https://radio.cock.institute/assets/playlists/kwsx_websex.m3u", "https://azura.drmnbss.org:8000/radio.mp3?refresh=1740700461231", "http://www.globalnetworkradio.com:8000/BF6", } url:Dock(FILL);url:SetPaintBackground(false) url:SetValue(GetConVar("cl_webradio_url"):GetString()) url:SetTextColor(Color(255,255,255)) url:SetKeyboardInputEnabled(true) url.OnGetFocus = function(self) url:SetHighlightColor(Color(0,255,0)) if window.pinned then RunConsoleCommand("+menu_context") end end --url:SetHistoryEnabled(true) url.OnValueChange = function(self) if window.pinned then RunConsoleCommand("-menu_context") end end local more = vgui.Create("DButton", field) more:Dock(RIGHT) more:SetSize(32) --prevChapter:SetPos(pausePlay:GetPos()+32) more:SetText("...") more:SetColor(Color(255,255,255)) more.DoClick=function(self) print('memes') end more.Paint = function() --surface.DrawOutlinedRect(0, 0, newpanel:GetWide(), newpanel:GetTall() - 2, 1) surface.SetTexture(surface.GetTextureID("gui/gradient_down")) surface.SetDrawColor(32,32,64,255) more:DrawTexturedRect() end local newpanel=vgui.Create("DFrame",window) newpanel:SetTitle("") newpanel:Dock(TOP);newpanel:SetTall(32); newpanel:ShowCloseButton(false) newpanel:SetDraggable(false) newpanel.Paint = function() --draw.RoundedBox(0, 0, 0, newpanel:GetWide(), newpanel:GetTall(), Color(255,255,255)) surface.SetDrawColor(255,255,255,255) --surface.DrawOutlinedRect(0, 0, newpanel:GetWide(), newpanel:GetTall() - 2, 1) surface.SetTexture(surface.GetTextureID("gui/gradient_up")) surface.SetDrawColor(0,0,32,255) newpanel:DrawTexturedRect() --newpanel:InvalidateLayout(true) --newpanel:SizeToChildren(false,true) end local prevChapter = vgui.Create("DButton", newpanel) prevChapter:SetSize(32,newpanel:GetTall()) --prevChapter:SetPos(pausePlay:GetPos()+32) prevChapter:SetFont("DermaLarge");prevChapter:SetColor(Color(255,255,255)) prevChapter:SetText("⏮") prevChapter.DoClick=function(self) if indexPos <= 1 then indexPos = table.maxn(urls) else indexPos=indexPos-1 end for k,v in pairs(urls) do if indexPos == k then GetConVar("cl_webradio_url"):SetString(v) url:SetValue(GetConVar("cl_webradio_url"):GetString()) np:SetText("⟳ Loading...");np:SizeToContents() end end end prevChapter.Paint = function() --surface.DrawOutlinedRect(0, 0, newpanel:GetWide(), newpanel:GetTall() - 2, 1) surface.SetTexture(surface.GetTextureID("gui/gradient_down")) surface.SetDrawColor(32,32,64,0) prevChapter:DrawTexturedRect() end local pausePlay = vgui.Create("DButton", newpanel) pausePlay:SetPos(prevChapter:GetPos()+32) pausePlay:SetSize(32,newpanel:GetTall()) pausePlay:SetFont("DermaLarge");pausePlay:SetColor(Color(255,255,255)) local function xyz() if GetConVar("cl_webradio"):GetBool() then pausePlay:SetText("⏸") else pausePlay:SetText("⏵") end end xyz();pausePlay.DoClick=function(self) if GetConVar("cl_webradio"):GetBool() then GetConVar("cl_webradio"):SetBool(false) else GetConVar("cl_webradio"):SetBool(true) end xyz() end pausePlay.Paint = function() --surface.DrawOutlinedRect(0, 0, newpanel:GetWide(), newpanel:GetTall() - 2, 1) surface.SetTexture(surface.GetTextureID("gui/gradient_down")) surface.SetDrawColor(32,32,64,0) pausePlay:DrawTexturedRect() end local nextChapter = vgui.Create("DButton", newpanel) nextChapter:SetSize(32,newpanel:GetTall()) nextChapter:SetPos(pausePlay:GetPos()+32) nextChapter:SetFont("DermaLarge");nextChapter:SetColor(Color(255,255,255)) nextChapter:SetText("⏭") nextChapter.DoClick=function(self) if indexPos >= table.maxn(urls) then indexPos = 1 else indexPos=indexPos+1 end for k,v in pairs(urls) do if indexPos == k then GetConVar("cl_webradio_url"):SetString(v) url:SetValue(GetConVar("cl_webradio_url"):GetString()) np:SetText("⟳ Loading...");np:SizeToContents() end end end nextChapter.Paint = function() --surface.DrawOutlinedRect(0, 0, newpanel:GetWide(), newpanel:GetTall() - 2, 1) surface.SetTexture(surface.GetTextureID("gui/gradient_down")) surface.SetDrawColor(32,32,64,0) nextChapter:DrawTexturedRect() end local volume = vgui.Create( "DSlider", newpanel ) volume:SetPos( nextChapter:GetX() + (nextChapter:GetWide() + 8), nextChapter:GetY() + 8+2) volume:SetSize( 296, 20 ) volume:SetConVarX("cl_webradio_volume") volume.Paint = function() surface.SetDrawColor(128,128,128,255) surface.DrawRect(0, 8, volume:GetWide()*volume:GetSlideX(), volume:GetTall() - 16) end local pin = vgui.Create("DImageButton", window) pin:SetSize(16,16) pin:SetPos(window:GetWide()-48,4) --pin:SetSize(128,16) --pin:SetText("Pin to HUD overlay") --pin:SetText("📌") pin:SetImage("icon16/contrast.png") pin.DoClick = function(self) if !window.pinned then window.pinned = true elseif window.pinned then window.pinned = false end -- pinned meaning in-game overlay drawing on-top if window.pinned then window.opacity=window.opacity/2 window:SetMouseInputEnabled(false) window:SetKeyboardInputEnabled(false) --pin:SetText("Unpin from HUD overlay") -- so if we're pinned , and we want to open the context menu to interact with the pinned object hook.Add( "OnContextMenuOpen", "cl_webradio_pin", function() if(ispanel(window)) then window.opacity=window.opacity*2 window:SetMouseInputEnabled(true) window:SetKeyboardInputEnabled(true) end end )hook.Add( "OnContextMenuClose", "cl_webradio_unpin", function() if(ispanel(window)) then if window.pinned then window.opacity=window.opacity/2 window:SetMouseInputEnabled(false) window:SetKeyboardInputEnabled(false) end end end ) elseif not window.pinned then window:Close() hook.Remove("OnContextMenuOpen","cl_webradio_pin") hook.Remove("OnContextMenuClose","cl_webradio_unpin") end end local close = vgui.Create("DButton", window) close:SetSize(24,24) close:SetPos(window:GetWide()-24,0) close:SetText("X") close:SetColor(Color(255,255,255,window.opacity)) close.DoClick = function(self) window:Close() end close.Paint = function() --surface.DrawOutlinedRect(0, 0, newpanel:GetWide(), newpanel:GetTall() - 2, 1) surface.SetDrawColor(255,0,0,window.opacity) surface.DrawRect(0, 0, close:GetWide(), close:GetTall()) end --[[ local control = vgui.Create("DCollapsibleCategory", window) control:Dock(TOP) control:SetLabel("Music controls") control:SetExpanded(false) control.PaintOver = function() window:InvalidateLayout(true) window:SizeToChildren(false,true) end local panel = vgui.Create("DListLayout", control) panel:DockMargin(8,8,8,8) control:SetContents(panel) local toggle = vgui.Create("DCheckBoxLabel", panel) toggle:SetText("Enabled") toggle:SetConVar("cl_webradio") toggle:SizeToContents() local pausePlay = vgui.Create("DButton", panel) pausePlay:SetSize(32,32);pausePlay:SetFont("DermaLarge") local function xyz() if GetConVar("cl_webradio"):GetBool() then pausePlay:SetText("⏸") else pausePlay:SetText("⏵") end end xyz();pausePlay.DoClick=function(self) if GetConVar("cl_webradio"):GetBool() then GetConVar("cl_webradio"):SetBool(false) else GetConVar("cl_webradio"):SetBool(true) end xyz() end local volume = vgui.Create("DNumSlider", panel) --volume:SetText("Volume") volume:SetConVar("cl_webradio_volume") volume:SetMin(0);volume:SetMax(2);volume:SetDecimals(1) volume:SizeToContents()]] window:InvalidateLayout(true) window:SizeToChildren(false,true) end concommand.Add("cl_webradio_menu", show_settings)