Skip to content

Commit

Permalink
Update duration for streams to fix playlist advancement (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
Et0h committed Mar 4, 2021
1 parent 54cebbe commit 9441d85
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions syncplay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def getValueForOS(constantDict):
MPC_MIN_VER = "1.6.4"
MPC_BE_MIN_VER = "1.5.2.3123"
VLC_MIN_VERSION = "2.2.1"
VLC_INTERFACE_VERSION = "0.3.6"
VLC_INTERFACE_VERSION = "0.3.7"
VLC_LATENCY_ERROR_THRESHOLD = 2.0
MPV_UNRESPONSIVE_THRESHOLD = 60.0
CONTROLLED_ROOMS_MIN_VERSION = "1.3.0"
Expand Down Expand Up @@ -287,7 +287,7 @@ def getValueForOS(constantDict):
MPV_SUPERSEDE_IF_DUPLICATE_COMMANDS = ["set_property time-pos ", "loadfile "]
MPV_REMOVE_BOTH_IF_DUPLICATE_COMMANDS = ["cycle pause"]
MPLAYER_ANSWER_REGEX = "^ANS_([a-zA-Z_-]+)=(.+)$|^(Exiting)\.\.\. \((.+)\)$"
VLC_ANSWER_REGEX = r"(?:^(?P<command>[a-zA-Z_]+)(?:\: )?(?P<argument>.*))"
VLC_ANSWER_REGEX = r"(?:^(?P<command>[a-zA-Z_-]+)(?:\: )?(?P<argument>.*))"
UI_COMMAND_REGEX = r"^(?P<command>[^\ ]+)(?:\ (?P<parameter>.+))?"
UI_OFFSET_REGEX = r"^(?:o|offset)\ ?(?P<sign>[/+-])?(?P<time>\d{1,9}(?:[^\d\.](?:\d{1,9})){0,2}(?:\.(?:\d{1,3}))?)$"
UI_SEEK_REGEX = r"^(?:s|seek)?\ ?(?P<sign>[+-])?(?P<time>\d{1,4}(?:[^\d\.](?:\d{1,6})){0,2}(?:\.(?:\d{1,3}))?)$"
Expand Down
7 changes: 6 additions & 1 deletion syncplay/players/vlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def lineReceived(self, line):
# value = value.decode('utf-8')
self._filepath = value
self._pathAsk.set()
elif name == "duration":
elif name == "duration" or name == "duration-change":
if value == "no-input":
self._duration = 0
elif value == "invalid-32-bit-value":
Expand All @@ -306,6 +306,11 @@ def lineReceived(self, line):
else:
self._duration = float(value.replace(",", "."))
self._durationAsk.set()
if name == "duration-change":
self._filechanged = True
t = threading.Thread(target=self._onFileUpdate)
t.setDaemon(True)
t.start()
elif name == "playstate":
self._paused = bool(value != 'playing') if (value != "no-input" and self._filechanged == False) else self._client.getGlobalPaused()
diff = time.time() - self._lastVLCPositionUpdate if self._lastVLCPositionUpdate else 0
Expand Down
20 changes: 14 additions & 6 deletions syncplay/resources/lua/intf/syncplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Principal author: Etoh
Other contributors: DerGenaue, jb, Pilotat
Project: https://syncplay.pl/
Version: 0.3.6
Version: 0.3.7
Note:
* This interface module is intended to be used in conjunction with Syncplay.
Expand Down Expand Up @@ -78,7 +78,7 @@ Syncplay should install this automatically to your user folder.
--]==========================================================================]

local connectorversion = "0.3.6"
local connectorversion = "0.3.7"
local vlcversion = vlc.misc.version()
local vlcmajorversion = tonumber(vlcversion:sub(1,1)) -- get the major version of VLC

Expand Down Expand Up @@ -114,6 +114,8 @@ local newfilepath
local newinputstate
local oldtitle = 0
local newtitle = 0
local oldduration = 0
local newduration = 0

local channel1
local channel2
Expand Down Expand Up @@ -179,6 +181,11 @@ function detectchanges()
oldtitle = newtitle
notificationbuffer = notificationbuffer .. "playstate"..msgseperator..tostring(get_play_state())..msgterminator
notificationbuffer = notificationbuffer .. "position"..msgseperator..tostring(get_time())..msgterminator
newduration = get_duration()
if oldduration ~= newduration then
oldduration = newduration
notificationbuffer = notificationbuffer .. "duration-change"..msgseperator..tostring(newduration)..msgterminator
end
else
notificationbuffer = notificationbuffer .. "playstate"..msgseperator..noinput..msgterminator
notificationbuffer = notificationbuffer .. "position"..msgseperator..noinput..msgterminator
Expand All @@ -189,7 +196,6 @@ function detectchanges()
oldinputstate = newinputstate
notificationbuffer = notificationbuffer.."inputstate-change"..msgseperator..tostring(newinputstate)..msgterminator
end

return notificationbuffer
end

Expand Down Expand Up @@ -406,7 +412,7 @@ function get_duration ()
local i = 0
response = 0
repeat
vlc.misc.mwait(vlc.misc.mdate() + durationdelay)
-- vlc.misc.mwait(vlc.misc.mdate() + durationdelay)
if item and item:duration() then
response = item:duration()
if response < 1 then
Expand All @@ -420,7 +426,6 @@ function get_duration ()
else
errormsg = noinput
end

return response, errormsg
end

Expand Down Expand Up @@ -490,7 +495,10 @@ function do_command ( command, argument)

if command == "get-interface-version" then response = "interface-version"..msgseperator..connectorversion..msgterminator
elseif command == "get-vlc-version" then response = "vlc-version"..msgseperator..vlcversion..msgterminator
elseif command == "get-duration" then response = "duration"..msgseperator..errormerge(get_duration())..msgterminator
elseif command == "get-duration" then
newduration = errormerge(get_duration())
response = "duration"..msgseperator..newduration..msgterminator
oldduration = newduration
elseif command == "get-filepath" then response = "filepath"..msgseperator..errormerge(get_filepath())..msgterminator
elseif command == "get-filename" then response = "filename"..msgseperator..errormerge(get_filename())..msgterminator
elseif command == "get-title" then response = "title"..msgseperator..errormerge(get_var("title", 0))..msgterminator
Expand Down

0 comments on commit 9441d85

Please sign in to comment.