I'm trying to make a simple Youtube player?

I am trying to make a simple youtube music player. I want the frame to be invisible and just play music when someone types “dj_url URL OF SONG” I just get errors.



concommand.Add( "dj_url", function( ply, text )
local playerInput = string.Explode( " ", text );

local frame = vgui.Create( "DFrame" )
frame:MakePopup()

local html = vgui.Create( "HTML", frame )
html:Dock( FILL )
html:OpenURL( playerInput[2] )
end
)


Posting the error messages increases your chances of getting help.




[ERROR] addons/getaddons/lua/autorun/client/djme.lua:9: bad argument #1 to 'OpenURL' (string expected, got nil)
  1. OpenURL - [C]:-1
   2. unknown - addons/getaddons/lua/autorun/client/djme.lua:9
    3. unknown - lua/includes/modules/concommand.lua:54



Use the arguments (3rd argument of the function) instead.

Here you go-



concommand.Add( "dj_url", function( ply, cmd, args, argsString )

local html = vgui.Create( "DHTML" )
html:OpenURL( argsString )
html:SetVisible( false )

end )


It does exactly what you wanted it to, but make sure the URL doesn’t have https:// in front of it, or the double slashes mess it up (although there’s probably a way to fix this). Don’t worry, the URL still loads fine without the https://
If you want it to be even simpler, you could do



concommand.Add( "dj_url", function( ply, cmd, args, argsString )

local html = vgui.Create( "DHTML" )
html:OpenURL( "www.youtube.com/watch?v="..argsString )
html:SetVisible( false )

end )


Then, all you need to do is type whatever is after watch?v= of a video and it’d work.

Thank you for the help!