Merge pull request #112 from thomabx/playstate
Reports playback status to the server
This commit is contained in:
commit
dcc067f11a
|
@ -2,6 +2,10 @@
|
|||
<component name="JFVideo" extends="Video">
|
||||
<interface>
|
||||
<field id="backPressed" type="boolean" alwaysNotify="true" />
|
||||
<field id="PlaySessionId" type="string" />
|
||||
</interface>
|
||||
<script type="text/brightscript" uri="JFVideo.brs" />
|
||||
<children>
|
||||
<timer id="playbackTimer" repeat="true" duration="30" />
|
||||
</children>
|
||||
</component>
|
||||
|
|
|
@ -39,6 +39,9 @@ sub Main()
|
|||
print "CLOSING SCREEN"
|
||||
return
|
||||
else if isNodeEvent(msg, "backPressed")
|
||||
if msg.getRoSGNode().focusedChild <> invalid and msg.getRoSGNode().focusedChild.isSubtype("JFVideo")
|
||||
stopPlayback()
|
||||
end if
|
||||
' Pop a group off the stack and expose what's below
|
||||
n = m.scene.getChildCount() - 1
|
||||
if n = 1
|
||||
|
@ -156,6 +159,7 @@ sub Main()
|
|||
m.scene.appendChild(group)
|
||||
group.setFocus(true)
|
||||
group.control = "play"
|
||||
ReportPlayback(group, "start")
|
||||
m.overhang.visible = false
|
||||
else if isNodeEvent(msg, "search_value")
|
||||
query = msg.getRoSGNode().search_value
|
||||
|
@ -208,6 +212,7 @@ sub Main()
|
|||
m.scene.appendChild(group)
|
||||
group.setFocus(true)
|
||||
group.control = "play"
|
||||
ReportPlayback(group, "start")
|
||||
m.overhang.visible = false
|
||||
else if btn.id = "watched-button"
|
||||
movie = group.itemContent
|
||||
|
@ -262,6 +267,15 @@ sub Main()
|
|||
wipe_groups()
|
||||
goto app_start
|
||||
end if
|
||||
else if isNodeEvent(msg, "fire")
|
||||
ReportPlayback(group, "update")
|
||||
else if isNodeEvent(msg, "state")
|
||||
node = msg.getRoSGNode()
|
||||
if node.state = "finished" then
|
||||
node.backPressed = "true"
|
||||
else if node.state = "playing" or node.state = "paused" then
|
||||
ReportPlayback(group, "update")
|
||||
end if
|
||||
else
|
||||
print type(msg)
|
||||
print msg
|
||||
|
|
|
@ -344,9 +344,12 @@ end function
|
|||
function CreateVideoPlayerGroup(video_id)
|
||||
' Video is Playing
|
||||
video = VideoPlayer(video_id)
|
||||
timer = video.findNode("playbackTimer")
|
||||
|
||||
video.observeField("backPressed", m.port)
|
||||
video.observeField("state", m.port)
|
||||
timer.control = "start"
|
||||
timer.observeField("fire", m.port)
|
||||
|
||||
return video
|
||||
end function
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
function VideoPlayer(id)
|
||||
' Get video controls and UI
|
||||
video = CreateObject("roSGNode", "JFVideo")
|
||||
video.content = VideoContent(id)
|
||||
video.id = id
|
||||
video = VideoContent(video)
|
||||
|
||||
jellyfin_blue = "#00a4dcFF"
|
||||
|
||||
|
@ -11,38 +12,45 @@ function VideoPlayer(id)
|
|||
return video
|
||||
end function
|
||||
|
||||
function VideoContent(id) as object
|
||||
function VideoContent(video) as object
|
||||
' Get video stream
|
||||
content = createObject("RoSGNode", "ContentNode")
|
||||
video.content = createObject("RoSGNode", "ContentNode")
|
||||
|
||||
meta = ItemMetaData(id)
|
||||
content.title = meta.Name
|
||||
meta = ItemMetaData(video.id)
|
||||
video.content.title = meta.Name
|
||||
container = getContainerType(meta)
|
||||
video.PlaySessionId = ItemGetSession(video.id)
|
||||
|
||||
if directPlaySupported(meta) then
|
||||
content.url = buildURL(Substitute("Videos/{0}/stream", id), {
|
||||
video.content.url = buildURL(Substitute("Videos/{0}/stream", video.id), {
|
||||
"PlaySessionId": video.PlaySessionId
|
||||
Static: "true",
|
||||
Container: container
|
||||
})
|
||||
content.streamformat = container
|
||||
content.switchingStrategy = ""
|
||||
video.content.streamformat = container
|
||||
video.content.switchingStrategy = ""
|
||||
else
|
||||
content.url = buildURL(Substitute("Videos/{0}/master.m3u8", id), {
|
||||
PlaySessionId: ItemGetSession(id)
|
||||
VideoCodec: "h264",
|
||||
AudioCodec: "aac",
|
||||
MediaSourceId: id,
|
||||
video.content.url = buildURL(Substitute("Videos/{0}/master.m3u8", video.id), {
|
||||
"PlaySessionId": video.PlaySessionId
|
||||
"VideoCodec": "h264",
|
||||
"AudioCodec": "aac",
|
||||
"MediaSourceId": video.id,
|
||||
"SegmentContainer": "ts",
|
||||
"MinSegments": 1,
|
||||
"BreakOnNonKeyFrames": "True",
|
||||
"h264-profile": "high,main,baseline,constrainedbaseline",
|
||||
"RequireAvc": "false",
|
||||
})
|
||||
end if
|
||||
content = authorize_request(content)
|
||||
video.content = authorize_request(video.content)
|
||||
|
||||
' todo - audioFormat is read only
|
||||
content.audioFormat = getAudioFormat(meta)
|
||||
video.content.audioFormat = getAudioFormat(meta)
|
||||
|
||||
if server_is_https() then
|
||||
content.setCertificatesFile("common:/certs/ca-bundle.crt")
|
||||
video.content.setCertificatesFile("common:/certs/ca-bundle.crt")
|
||||
end if
|
||||
return content
|
||||
return video
|
||||
end function
|
||||
|
||||
function directPlaySupported(meta as object) as boolean
|
||||
|
@ -84,3 +92,21 @@ function getAudioInfo(meta as object) as object
|
|||
end for
|
||||
return results
|
||||
end function
|
||||
|
||||
function ReportPlayback(video, state = "update" as string)
|
||||
params = {
|
||||
"PlaySessionId": video.PlaySessionId,
|
||||
"PositionTicks": str(int(video.position))+"0000000",
|
||||
"IsPaused": (video.state = "paused"),
|
||||
}
|
||||
PlaystateUpdate(video.id, state, params)
|
||||
end function
|
||||
|
||||
function StopPlayback()
|
||||
video = m.scene.focusedchild
|
||||
video.findNode("playbackTimer").control = "stop"
|
||||
video.control = "stop"
|
||||
video.visible = "false"
|
||||
if video.status = "finished" then MarkItemWatched(video.id)
|
||||
ReportPlayback(video,"stop")
|
||||
end function
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
function PlaystateStart(id, params)
|
||||
function PlaystateUpdate(id, state as string, params = {})
|
||||
if state = "start" then
|
||||
url = "Sessions/Playing"
|
||||
else if state = "stop" then
|
||||
url = "Sessions/Playing/Stopped"
|
||||
else if state = "update"
|
||||
url = "Sessions/Playing/Progress"
|
||||
end if
|
||||
params = PlaystateDefaults(id, params)
|
||||
resp = APIRequest("Sessions/Playing")
|
||||
return postJson(resp, params)
|
||||
end function
|
||||
|
||||
function PlaystateUpdate(id, params)
|
||||
params = PlaystateDefaults(id, params)
|
||||
resp = APIRequest("Sessions/Playing/Progress")
|
||||
return postJson(resp, params)
|
||||
end function
|
||||
|
||||
function PlaystateStop(id, params={})
|
||||
params = PlaystateDefaults(id, params)
|
||||
resp = APIRequest("Sessions/Playing/Stopped")
|
||||
resp = APIRequest(url)
|
||||
return postJson(resp, params)
|
||||
end function
|
||||
|
||||
|
@ -29,7 +24,7 @@ function PlaystateDefaults(id="" as string, params={} as object)
|
|||
'"SubtitleStreamIndex": 0,
|
||||
"IsPaused": false,
|
||||
'"IsMuted": false,
|
||||
'"PositionTicks": 0,
|
||||
"PositionTicks": 0,
|
||||
'"PlaybackStartTimeTicks": 0,
|
||||
'"VolumeLevel": 100,
|
||||
'"Brightness": 100,
|
||||
|
|
Loading…
Reference in New Issue
Block a user