Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then
- util.AddNetworkString("playx_sync")
- AddCSLuaFile()
- local conv = CreateConVar("playx_sync_startdelay", 10, FCVAR_ARCHIVE, "How many seconds to wait before starting the video")
- hook.Add("PlayXMediaBegun","synctime",function(data)
- local handler = data[1]
- local url = data[2]
- SetGlobal2Float("PlayXStartTime",CurTime() + conv:GetFloat())
- print("Starting in " .. conv:GetFloat() .. " seconds")
- end)
- net.Receive("playx_sync",function(len, ply)
- if not PlayX.CurrentMedia then return end
- net.Start("playx_sync")
- net.WriteString(PlayX.CurrentMedia.Handler)
- net.WriteTable(PlayX.CurrentMedia.HandlerArgs)
- net.WriteBool(PlayX.CurrentMedia.LowFramerate)
- net.WriteBool(PlayX.CurrentMedia.ResumeSupported)
- net.WriteString(PlayX.CurrentMedia.URI)
- net.Send(ply)
- end)
- local paused
- concommand.Add("playx_server_pause", function(ply)
- if not ply:IsSuperAdmin() then return end
- paused = CurTime() - GetGlobal2Float("PlayXStartTime")
- SetGlobal2Bool("PlayXPaused", true)
- for k, ply in ipairs(player.GetAll()) do ply:ConCommand("playx_manual_pause") end
- end)
- concommand.Add("playx_server_play", function(ply)
- if not ply:IsSuperAdmin() or not paused then return end
- SetGlobal2Float("PlayXStartTime",CurTime() + paused)
- SetGlobal2Bool("PlayXPaused", false)
- paused = nil
- for k, ply in ipairs(player.GetAll()) do ply:ConCommand("playx_syncme") end
- end)
- end
- if CLIENT then
- local handlers = {}
- handlers.JWVideo = function()
- local playxpanel = ents.FindByClass("gmod_playx")[1].Browser
- playxpanel:SetPos(-playxpanel:GetSize(),0)
- local CONTROLS = {}
- local pending
- playxpanel:AddFunction("ctrl","cb",function(dt) if pending then pending(dt) pending = nil end end)
- CONTROLS.GetTime = function(cb)
- pending = function(a)
- cb(tonumber(a))
- end
- playxpanel:Call("ctrl.cb(document.getElementsByTagName('video')[0].currentTime);")
- end
- CONTROLS.SetTime = function(time)
- playxpanel:Call("document.getElementsByTagName('video')[0].currentTime = " .. time .. ";")
- end
- CONTROLS.Play = function(time)
- playxpanel:Call("document.getElementsByTagName('video')[0].play();")
- end
- CONTROLS.Pause = function(time)
- playxpanel:Call("document.getElementsByTagName('video')[0].pause();")
- end
- return CONTROLS
- end
- handlers.JW = handlers.JWVideo
- handlers.YoutubeNative = handlers.JWVideo
- handlers.Vimeo = handlers.JWVideo
- handlers["justin.tv"] = handlers.JWVideo
- handlers.Hulu = handlers.JWVideo
- handlers.FlashAPI = handlers.JWVideo --Actually not sure about this one, it's used by the google drive provider so I added it anyway
- local function getcontrols(handler)
- if not handlers[handler] then print("no controls for handler " .. handler .. ", trying JWVideo") return handlers.JWVideo() end
- return handlers[handler]()
- end
- local currentcontrols
- local function dosync()
- local CONTROLS = getcontrols(PlayX.CurrentMedia.Handler)
- if not CONTROLS then return end
- if GetGlobal2Bool("PlayXPaused", false) then return end
- local start = GetGlobal2Float("PlayXStartTime")
- print("starting in " .. math.max(0, start - CurTime()) .. " seconds")
- timer.Simple(math.max(0, start - CurTime()), function()
- CONTROLS.SetTime(math.max(0, CurTime() - start))
- CONTROLS.Play()
- print("starting at " .. math.max(0, CurTime() - start) .. " seconds")
- end)
- end
- hook.Add("PlayXPlayBegun","synctime",function(data) timer.Simple(3,function()
- local CONTROLS = getcontrols(data[1])
- if not CONTROLS then return ErrorNoHalt("couldn't get controls for PlayX Panel!") end
- CONTROLS.Pause()
- currentcontrols = CONTROLS
- dosync()
- end) end)
- concommand.Add("playx_syncme", dosync)
- concommand.Add("playx_manual_pause", function() getcontrols(PlayX.CurrentMedia.Handler).Pause() end)
- concommand.Add("playx_manual_play", function() getcontrols(PlayX.CurrentMedia.Handler).Play() end)
- concommand.Add("playx_manual_settime", function(_, _, a) getcontrols(PlayX.CurrentMedia.Handler).SetTime(a[1]) end)
- concommand.Add("playx_manual_gettime", function() getcontrols(PlayX.CurrentMedia.Handler).GetTime(print) end)
- concommand.Add("playx_manual_fixplayer", function()
- if not PlayX.CurrentMedia then
- net.Start("playx_sync")
- net.SendToServer()
- return
- end
- ents.FindByClass("gmod_playx")[1]:Play(
- PlayX.CurrentMedia.Handler,
- PlayX.CurrentMedia.URI,
- CurTime()-GetGlobal2Float("PlayXStartTime"),
- GetConVar("playx_volume"):GetFloat(),
- PlayX.CurrentMedia.HandlerArgs)
- timer.Simple(5, dosync)
- end)
- net.Receive("playx_sync",function(len)
- PlayX.CurrentMedia = {
- Handler = net.ReadString(),
- HandlerArgs = net.ReadTable(),
- LowFramerate = net.ReadBool(),
- ResumeSupported = net.ReadBool(),
- StartTime = CurTime()-GetGlobal2Float("PlayXStartTime"),
- URI = net.ReadString()
- }
- RunConsoleCommand("playx_manual_fixplayer")
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment