I'm trying to make a GUI so when a player enters a youtube video ID it'll play the sound here my code.
I've been having troubles and can't figure it out.
I've managed to find an API that plays the sound but I'm kinda new to LUA and still don't really understand it I'm just trying to make this clientsided only for right now.
[CODE]
local AudioSource = nil
local videoID = ""
local function playSong()
http.Fetch( "http://youtubeinmp3.com/fetch/?api=advanced&format=json&video=https://www.youtube.com/watch?v="..videoID, function( body )
local json = util.JSONToTable(body)
PrintTable(json)
sound.PlayURL("http://navarr.me/ytaudio/?q="..videoID.."&psize=s&a=on&theme=dark", "mono", function(source)
if IsValid(source) then
AudioSource = source
source:Play()
LocalPlayer():ChatPrint("Now Playing: " ..json["title"])
else
LocalPlayer():ChatPrint("Invaild")
end
end)
end)
end
local frame = vgui.Create("DFrame")
frame:SetSize(800, 600)
frame:Center()
frame:SetTitle("TwistedLobby's Visualizer")
frame:MakePopup()
frame:SetDraggable(true)
frame:ShowCloseButton(true)
local PropertySheet = vgui.Create( "DPropertySheet", frame )
PropertySheet:SetPos( 5, 30 )
PropertySheet:SetSize( 790, 565 )
PropertySheet:AddSheet( "JUST TESTING", SheetItemOne, "gui/icons/tux.png", false, false, "LOL" )
PropertySheet:AddSheet( "ANOTHER TEST", SheetItemTwo, "gui/icons/group.png", false, false, "LOL" )
local TextEntry = vgui.Create( "DTextEntry", SheetItemOne ) -- create the form as a child of frame
TextEntry:SetPos( 25, 50 )
TextEntry:SetSize( 150, 25 )
TextEntry:SetText( "" )
TextEntry.OnEnter = function( self )
if(TextEntry:GetText() == "") then
TextEntry:SetText("Invalid YouTube URL")
else
videoID = TextEntry:GetText()
playSong()
end
end
[/CODE]
BUMP
That's clientsided actually...
[QUOTE=gonzalolog;51953645]That's clientsided actually...[/QUOTE]
I'm new to LUA & really don't understand it but I threw this together and can't figure out why it won't play the music/sound.
It just prints to console saying NIL when I hit enter with a video id.
- It's not LUA it's just lua ([url]https://www.lua.org/about.html[/url])
- The second website your fetching from is returning an HTML document, not audio data
- YouTube's​ videos are all in a compressed mp4 format and are served over DASH (example of this library: [url]https://github.com/google/shaka-player[/url])
A better method to do is just use a service which serves mp3 or any other audio format. I have an example of this usage on my ulx command for SoundCloud ([url]https://gist.github.com/mrpotatofactory/f973b57365c1597dd6eb8ac90becbd51/[/url])
Best of luck!
Sorry, you need to Log In to post a reply to this thread.