requestBrowserDomains({"www.convertmp3.io"})
local browser = createBrowser( 1, 1, false )
local currentSound = {}
addEvent( 'Play' , true )
addEventHandler( 'Play' , root ,
function( link )
local vehicle = getPedOccupiedVehicle ( source )
local x, y, z = getElementPosition(vehicle)
currentSound[source] = playSound3D( link, x, y, z )
attachElements(currentSound[source],vehicle)
setSoundMaxDistance(currentSound[source],30)
setSoundVolume(currentSound[source],50)
end
)
function fetch(_,url)
if url and url ~= "" then
fetchRemote("http://www.convertmp3.io/fetch/?format=JSON&video="..url, callback)
end
end
addCommandHandler("p",fetch)
function callback(data, error)
if (error ~= 0) then
return outputChatBox(error)
end
if (data == "ERROR") then
return outputChatBox("data error")
end
local data = fromJSON("["..data.."]")
if (data) then
outputChatBox("Title: "..data.title)
outputChatBox("Length: "..data.length)
outputChatBox("Link: "..data.link)
loadBrowserURL( browser, data.link )
end
end
addEventHandler( "onClientBrowserNavigate", browser, function( link )
if not link:find("www.convertmp3.io") then
triggerServerEvent( 'play' , localPlayer , link ) -- trigger the event when the script actially gets the playable link!
end
end
)