Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto play the next TV episode #317

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/JFVideo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
12 changes: 12 additions & 0 deletions source/Main.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -397,13 +398,24 @@ 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")
else if isNodeEvent(msg, "state")
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
Expand Down
32 changes: 28 additions & 4 deletions source/VideoPlayer.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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