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.
[CODE]
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
)
[/CODE][QUOTE][/QUOTE]
Posting the error messages increases your chances of getting help.
[QUOTE=!cake;47587008]Posting the error messages increases your chances of getting help.[/QUOTE]
[CODE]
[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
[/CODE]
Use the arguments (3rd argument of the function) instead.
Here you go-
[CODE]
concommand.Add( "dj_url", function( ply, cmd, args, argsString )
local html = vgui.Create( "DHTML" )
html:OpenURL( argsString )
html:SetVisible( false )
end )
[/CODE]
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
[CODE]
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 )
[/CODE]
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!
Sorry, you need to Log In to post a reply to this thread.