Hello, first post here.
Code in question:
This is a modified version of the PlayX media query script off of GitHub.
The idea is to queue media with !q <search or url> or /q <search or url>.
Everything works lovely except the code commented “BUG”:
local function PlayNextInQueue(ply) if #MediaQueue > 0 then --sanity check PlayX.CloseMedia() Play(ply, "", MediaQueue, false) --Let PlayX autodetect the provider, just use a URL is_still_playing = true table.remove(MediaQueue, 1) --Remove the playing media from queue ---BUG: The below will always get nil since we have to wait for PlayX to load the media :c if PlayX.CurrentMedia["Length"] then timer.Simple(PlayX.CurrentMedia["Length"], PlayNextInQueue(ply)) end else PlayX.CloseMedia() --We've reached the end of the queue is_still_playing = false end end
Ideally, a timer is set to automatically play the next media item in the queue when the current media is finished.
After testing I’ve found that PlayX.CurrentMedia[“Length”] is nil until PlayX actually loads the media, which causes the timer to never begin, which results in my needing to skip a video that’s ended using my “/skip” chat command.
I would utilize a hook to wait to check the Length key but I can’t find information on any potential PlayX-specific hooks to use.
I’m using the PlayX addon from the Workshop and it is “up to date”.
I realize this script uses the now “old” PlayX API.
This is a script autorun on server, and I use it in the singleplayer mode (alone or with other users).
[editline]22nd August 2015[/editline]
If only this would work…
timer.Simple(3, function() timer.Simple(PlayX.CurrentMedia["Length"]-3, PlayNextInQueue(ply)) end)
…it would be perfect, but, since this line of code would be inside the PlayNextInQueue() function, it errors.
I literally need it to wait for a few seconds before grabbing the Length.
Nae Gevurah<sv_queuecommand.lua>:114: bad argument #2 to 'Simple' (function expected, got no value) 1. Simple - [C]:-1 2. unknown - Nae Gevurah<sv_queuecommand.lua>:114