Merge pull request #317 from cewert/autoplay-episodes

Auto play the next TV episode
This commit is contained in:
Charles Ewert 2020-12-02 12:00:50 -05:00 committed by GitHub
commit d165eee661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 4 deletions

View File

@ -13,6 +13,7 @@
<field id="decodeAudioSupported" type="boolean" />
<field id="isTranscoded" type="boolean" />
<field id="systemOverlay" type="boolean" value="false" />
<field id="showID" type="string" />
</interface>
<script type="text/brightscript" uri="JFVideo.brs" />
<children>

View File

@ -62,6 +62,7 @@ sub Main()
n = m.scene.getChildCount() - 1
if msg.getRoSGNode().focusedChild <> invalid and msg.getRoSGNode().focusedChild.isSubtype("JFVideo")
stopPlayback()
RemoveCurrentGroup()
else
if n = 1 then return
RemoveCurrentGroup()
@ -397,6 +398,12 @@ sub Main()
video = msg.getRoSGNode()
if video.position >= video.duration and not video.content.live then
stopPlayback()
if video.showID = invalid then
RemoveCurrentGroup()
else
MarkItemWatched(video.id)
playNextEpisode(video.id, video.showID)
end if
end if
else if isNodeEvent(msg, "fire")
ReportPlayback(group, "update")
@ -404,6 +411,11 @@ sub Main()
node = msg.getRoSGNode()
if node.state = "finished" then
stopPlayback()
if node.showID = invalid then
RemoveCurrentGroup()
else
playNextEpisode(node.id, node.showID)
end if
else if node.state = "playing" or node.state = "paused" then
ReportPlayback(group, "update")
end if

View File

@ -20,7 +20,8 @@ function VideoContent(video, audio_stream_idx = 1) as object
params = {}
meta = ItemMetaData(video.id)
video.content.title = meta.Name
video.content.title = meta.title
video.showID = meta.showID
' If there is a last playback positon, ask user if they want to resume
position = meta.json.UserData.PlaybackPositionTicks
@ -310,13 +311,11 @@ end function
function StopPlayback()
video = m.scene.focusedchild
if video.state = "finished" then MarkItemWatched(video.id)
video.control = "stop"
m.device.EnableAppFocusEvent(False)
video.findNode("playbackTimer").control = "stop"
video.visible = "false"
if video.status = "finished" then MarkItemWatched(video.id)
ReportPlayback(video, "stop")
RemoveCurrentGroup()
end function
function displaySubtitlesByUserConfig(subtitleTrack, audioTrack)
@ -337,3 +336,28 @@ function displaySubtitlesByUserConfig(subtitleTrack, audioTrack)
return false
end if
end function
function playNextEpisode(videoID as string, showID as string)
' query API for next episode ID
url = Substitute("Shows/{0}/Episodes", showID)
urlParams = { "UserId": get_setting("active_user")}
urlParams.Append({ "StartItemId": videoID })
urlParams.Append({ "Limit": 2 })
resp = APIRequest(url, urlParams)
data = getJson(resp)
if data <> invalid and data.Items.Count() = 2 then
' remove finished video node
n = m.scene.getChildCount() - 1
m.scene.removeChildIndex(n)
' setup new video node
nextVideo = CreateVideoPlayerGroup(data.Items[1].Id)
m.scene.appendChild(nextVideo)
nextVideo.setFocus(true)
nextVideo.control = "play"
ReportPlayback(nextVideo, "start")
else
' can't play next episode
RemoveCurrentGroup()
end if
end function