Begin tracking play state

This commit is contained in:
Nick Bisby 2019-03-18 20:11:34 -05:00
parent c088ce14ac
commit 18ccd45998
No known key found for this signature in database
GPG Key ID: F6E0C4E6D0B5EB36
3 changed files with 29 additions and 1 deletions

View File

@ -24,6 +24,8 @@ function buildURL(path as String, params={} as Object) as string
else if type(field.value) = "roInteger" then
item = field.key + "=" + req.escape(str(field.value).trim())
'item = field.key + "=" + str(field.value).trim()
else if type(field.value) = "roFloat" then
item = field.key + "=" + req.escape(str(field.value).trim())
else if field <> invalid
item = field.key + "=" + req.escape(field.value)
'item = field.key + "=" + field.value

View File

@ -424,16 +424,22 @@ sub showVideoPlayer(video_id)
while true
msg = wait(0, port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed() then
if video = invalid then return
progress = int( video.position / video.duration * 100)
if progress > 95 ' TODO - max resume percentage
MarkItemWatched(video_id)
end if
' TODO - report progress here
ticks = video.position * 10000000
ItemSessionStop(video_id, {"PositionTicks": ticks})
return
else if nodeEventQ(msg, "state")
state = msg.getData()
if state = "stopped" or state = "finished"
screen.close()
else if state = "playing"
ticks = video.position * 10000000
ItemSessionStart(video_id, {"PositionTicks": ticks})
end if
end if
end while

20
source/api_sessions.brs Normal file
View File

@ -0,0 +1,20 @@
function ItemSessionUpdate(id as String, params={})
url = "Sessions/Playing/Progress"
params.ItemId = id
resp = APIRequest(url, params)
return postJson(resp)
end function
function ItemSessionStart(id as String, params={})
url = "Sessions/Playing"
params.ItemId = id
resp = APIRequest(url, params)
return postJson(resp)
end function
function ItemSessionStop(id as String, params={})
url = "Sessions/Playing/Stopped"
params.ItemId = id
resp = APIRequest(url, params)
return postJson(resp)
end function