2023-05-26 23:04:20 +00:00
|
|
|
import "pkg:/source/utils/misc.brs"
|
|
|
|
|
2022-04-24 03:49:42 +00:00
|
|
|
sub init()
|
|
|
|
m.rows = m.top.findNode("tvEpisodeRow")
|
|
|
|
m.tvListOptions = m.top.findNode("tvListOptions")
|
|
|
|
|
|
|
|
m.rows.observeField("doneLoading", "rowsDoneLoading")
|
|
|
|
end sub
|
|
|
|
|
|
|
|
sub setupRows()
|
|
|
|
objects = m.top.objects
|
|
|
|
m.rows.objects = objects
|
|
|
|
end sub
|
|
|
|
|
|
|
|
sub rowsDoneLoading()
|
|
|
|
m.top.doneLoading = true
|
|
|
|
end sub
|
|
|
|
|
2023-05-21 12:25:58 +00:00
|
|
|
' List of video versions to choose from
|
|
|
|
sub SetUpVideoOptions(streams as object)
|
2023-05-20 23:33:42 +00:00
|
|
|
videos = []
|
|
|
|
|
|
|
|
for i = 0 to streams.Count() - 1
|
2023-05-26 22:52:15 +00:00
|
|
|
if LCase(streams[i].VideoType) = "videofile"
|
2023-05-20 23:33:42 +00:00
|
|
|
' Create options for user to switch between video tracks
|
|
|
|
videos.push({
|
|
|
|
"Title": streams[i].Name,
|
|
|
|
"Description": tr("Video"),
|
|
|
|
"Selected": m.top.objects.items[m.currentSelected].selectedVideoStreamId = streams[i].id,
|
|
|
|
"StreamID": streams[i].id,
|
|
|
|
"video_codec": streams[i].mediaStreams[0].displayTitle
|
|
|
|
})
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
|
|
|
if videos.count() >= 1
|
|
|
|
options = {}
|
|
|
|
options.videos = videos
|
|
|
|
m.tvListOptions.options = options
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
2023-05-21 12:25:58 +00:00
|
|
|
' List of audio tracks to choose from
|
|
|
|
sub SetUpAudioOptions(streams as object)
|
2022-04-24 03:49:42 +00:00
|
|
|
tracks = []
|
|
|
|
|
|
|
|
for i = 0 to streams.Count() - 1
|
|
|
|
if streams[i].Type = "Audio"
|
2023-05-21 12:25:58 +00:00
|
|
|
tracks.push({
|
|
|
|
"Title": streams[i].displayTitle,
|
|
|
|
"Description": streams[i].Title,
|
|
|
|
"Selected": m.top.objects.items[m.currentSelected].selectedAudioStreamIndex = i,
|
2023-05-26 23:04:20 +00:00
|
|
|
"StreamIndex": i
|
|
|
|
})
|
2022-04-24 03:49:42 +00:00
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
2023-05-20 23:33:42 +00:00
|
|
|
if tracks.count() >= 1
|
2022-04-24 03:49:42 +00:00
|
|
|
options = {}
|
2023-05-26 23:04:20 +00:00
|
|
|
if isValid(m.tvListOptions.options) and isValid(m.tvListOptions.options.videos)
|
2023-05-20 23:33:42 +00:00
|
|
|
options.videos = m.tvListOptions.options.videos
|
|
|
|
end if
|
2022-04-24 03:49:42 +00:00
|
|
|
options.audios = tracks
|
|
|
|
m.tvListOptions.options = options
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
sub audioOptionsClosed()
|
2023-05-06 21:54:30 +00:00
|
|
|
if m.currentSelected <> invalid
|
|
|
|
' If the user opened the audio options, we report back even if they left the selection alone.
|
|
|
|
' Otherwise, the users' lang peference from the server will take over.
|
2023-05-12 12:43:14 +00:00
|
|
|
' To do this, we interpret anything other than "0" as the user opened the audio options.
|
2023-05-06 21:54:30 +00:00
|
|
|
m.top.objects.items[m.currentSelected].selectedAudioStreamIndex = m.tvListOptions.audioStreamIndex = 0 ? 1 : m.tvListOptions.audioStreamIndex
|
2022-04-24 03:49:42 +00:00
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
2023-05-20 23:33:42 +00:00
|
|
|
sub videoOptionsClosed()
|
|
|
|
if m.tvListOptions.videoStreamId <> m.top.objects.items[m.currentSelected].selectedVideoStreamId
|
|
|
|
m.rows.objects.items[m.currentSelected].selectedVideoStreamId = m.tvListOptions.videoStreamId
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
2022-04-24 03:49:42 +00:00
|
|
|
function onKeyEvent(key as string, press as boolean) as boolean
|
|
|
|
if not press then return false
|
|
|
|
|
2023-05-26 23:04:20 +00:00
|
|
|
if key = "options" and isValid(m.rows.focusedChild) and isValid(m.rows.focusedChild.rowItemFocused)
|
2022-04-24 03:49:42 +00:00
|
|
|
m.currentSelected = m.rows.focusedChild.rowItemFocused[0]
|
|
|
|
mediaStreams = m.rows.objects.items[m.currentSelected].json.MediaStreams
|
2023-05-20 23:33:42 +00:00
|
|
|
mediaSources = m.rows.objects.items[m.currentSelected].json.MediaSources
|
2023-05-21 04:13:04 +00:00
|
|
|
if m.rows.objects.items[m.currentSelected].selectedVideoStreamId <> ""
|
|
|
|
for each source in mediaSources
|
|
|
|
if source.id = m.rows.objects.items[m.currentSelected].selectedVideoStreamId
|
|
|
|
mediaStreams = source.MediaStreams
|
|
|
|
exit for
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
end if
|
2023-05-26 23:04:20 +00:00
|
|
|
if isValid(mediaSources)
|
2023-05-20 23:33:42 +00:00
|
|
|
SetUpVideoOptions(mediaSources)
|
|
|
|
end if
|
2023-05-26 23:04:20 +00:00
|
|
|
if isValid(mediaStreams)
|
2023-05-20 23:33:42 +00:00
|
|
|
SetUpAudioOptions(mediaStreams)
|
|
|
|
end if
|
2023-05-26 23:04:20 +00:00
|
|
|
if isValid(m.tvListOptions.options)
|
2023-05-20 23:33:42 +00:00
|
|
|
m.tvListOptions.visible = true
|
|
|
|
m.tvListOptions.setFocus(true)
|
|
|
|
end if
|
2022-04-24 03:49:42 +00:00
|
|
|
return true
|
2022-04-26 12:01:53 +00:00
|
|
|
else if m.tvListOptions.visible = true and key = "back" or key = "options"
|
2022-04-24 03:49:42 +00:00
|
|
|
m.tvListOptions.setFocus(false)
|
|
|
|
m.tvListOptions.visible = false
|
|
|
|
m.rows.setFocus(true)
|
2023-05-20 23:33:42 +00:00
|
|
|
videoOptionsClosed()
|
2022-04-24 03:49:42 +00:00
|
|
|
audioOptionsClosed()
|
|
|
|
return true
|
|
|
|
else if key = "up" and m.rows.hasFocus() = false
|
|
|
|
m.rows.setFocus(true)
|
|
|
|
else if key = "down" and m.rows.hasFocus() = false
|
|
|
|
m.rows.setFocus(true)
|
|
|
|
end if
|
|
|
|
|
|
|
|
return false
|
|
|
|
end function
|