2020-03-28 20:04:57 +00:00
|
|
|
function selectSubtitleTrack(tracks, current = -1)
|
|
|
|
video = m.scene.focusedChild
|
|
|
|
trackSelected = selectSubtitleTrackDialog(video.Subtitles, video.SelectedSubtitle)
|
|
|
|
if trackSelected = -1 then
|
2020-03-29 14:56:48 +00:00
|
|
|
return invalid
|
2020-03-28 20:04:57 +00:00
|
|
|
else
|
|
|
|
return trackSelected - 1
|
|
|
|
end if
|
|
|
|
end function
|
|
|
|
|
|
|
|
function selectSubtitleTrackDialog(tracks, currentTrack = -1)
|
|
|
|
iso6392 = getSubtitleLanguages()
|
|
|
|
options = ["None"]
|
|
|
|
for each item in tracks
|
2020-04-04 17:21:43 +00:00
|
|
|
forced = ""
|
|
|
|
default = ""
|
|
|
|
if item.IsForced then forced = " [Forced]"
|
|
|
|
if item.IsDefault then default = " - Default"
|
2020-03-29 14:43:19 +00:00
|
|
|
if item.Track.Language <> invalid then
|
|
|
|
language = iso6392.lookup(item.Track.Language)
|
|
|
|
if language = invalid then language = item.Track.Language
|
|
|
|
else
|
|
|
|
language = "Undefined"
|
|
|
|
end if
|
2020-04-04 17:21:43 +00:00
|
|
|
options.push(language + forced + default)
|
2020-03-28 20:04:57 +00:00
|
|
|
end for
|
|
|
|
return option_dialog(options, "Select a subtitle track", currentTrack + 1)
|
|
|
|
end function
|
|
|
|
|
|
|
|
sub changeSubtitleDuringPlayback(newid)
|
|
|
|
if newid = invalid then return
|
|
|
|
if newid = -1 then
|
|
|
|
turnoffSubtitles()
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
|
|
|
|
video = m.scene.focusedChild
|
|
|
|
oldTrack = video.Subtitles[video.SelectedSubtitle]
|
|
|
|
newTrack = video.Subtitles[newid]
|
|
|
|
|
|
|
|
video.captionMode = video.globalCaptionMode
|
|
|
|
m.device.EnableAppFocusEvent(not newTrack.IsTextSubtitleStream)
|
|
|
|
video.SelectedSubtitle = newid
|
|
|
|
|
|
|
|
if newTrack.IsTextSubtitleStream then
|
2020-04-29 16:26:12 +00:00
|
|
|
if video.content.PlayStart > video.position
|
2020-03-28 20:04:57 +00:00
|
|
|
'User has rewinded to before playback was initiated. The Roku never loaded this portion of the text subtitle
|
|
|
|
'Changing the track will cause plaback to jump to initial bookmark position.
|
|
|
|
video.suppressCaptions = true
|
|
|
|
rebuildURL(false)
|
|
|
|
end if
|
|
|
|
video.subtitleTrack = video.availableSubtitleTracks[newTrack.TextIndex].TrackName
|
|
|
|
video.suppressCaptions = false
|
|
|
|
else
|
|
|
|
video.suppressCaptions = true
|
|
|
|
end if
|
|
|
|
|
|
|
|
'Rebuild URL if subtitle track is video or if changed from video subtitle to text subtitle.
|
|
|
|
if not newTrack.IsTextSubtitleStream then
|
|
|
|
rebuildURL(true)
|
|
|
|
else if oldTrack <> invalid and not oldTrack.IsTextSubtitleStream then
|
|
|
|
rebuildURL(false)
|
|
|
|
if newTrack.TextIndex > 0 then video.subtitleTrack = video.availableSubtitleTracks[newTrack.TextIndex].TrackName
|
|
|
|
end if
|
|
|
|
end sub
|
|
|
|
|
|
|
|
function turnoffSubtitles()
|
|
|
|
video = m.scene.focusedChild
|
|
|
|
current = video.SelectedSubtitle
|
|
|
|
video.SelectedSubtitle = -1
|
|
|
|
video.suppressCaptions = true
|
|
|
|
m.device.EnableAppFocusEvent(false)
|
|
|
|
if current > -1 and not video.Subtitles[current].IsTextSubtitleStream then
|
|
|
|
rebuildURL(false)
|
|
|
|
end if
|
|
|
|
end function
|
|
|
|
|
2020-03-11 03:50:47 +00:00
|
|
|
function systemOverlayClosed()
|
|
|
|
video = m.scene.focusedChild
|
|
|
|
if video.globalCaptionMode <> video.captionMode then
|
|
|
|
video.captionMode = video.globalCaptionMode
|
|
|
|
reviewSubtitleDisplay()
|
|
|
|
end if
|
|
|
|
end function
|
|
|
|
|
|
|
|
function reviewSubtitleDisplay()
|
|
|
|
'TODO handle changing subtitles tracks during playback
|
|
|
|
displayed = areSubtitlesDisplayed()
|
|
|
|
needed = areSubtitlesNeeded()
|
|
|
|
print "displayed: " displayed " needed: " needed
|
|
|
|
if areSubtitlesNeeded() and (not areSubtitlesDisplayed()) then
|
|
|
|
rebuildURL(true)
|
|
|
|
else if areSubtitlesDisplayed() and (not areSubtitlesNeeded()) then
|
|
|
|
rebuildURL(false)
|
|
|
|
end if
|
|
|
|
end function
|
|
|
|
|
|
|
|
function areSubtitlesDisplayed()
|
|
|
|
index = m.scene.focusedChild.transcodeParams.lookup("SubtitleStreamIndex")
|
|
|
|
if index <> invalid and index <> -1 then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end if
|
|
|
|
end function
|
|
|
|
|
|
|
|
function areSubtitlesNeeded()
|
|
|
|
captions = m.scene.focusedChild.globalCaptionMode
|
|
|
|
if captions = "On"
|
|
|
|
return true
|
|
|
|
else if captions = "Off"
|
|
|
|
return false
|
|
|
|
else if captions = "When mute"
|
|
|
|
return m.mute
|
|
|
|
else if captions = "Instant replay"
|
|
|
|
'Unsupported. Do we want to do this? Is it worth transcoding for rewinded content and then untranscoding?
|
|
|
|
return false
|
|
|
|
end if
|
|
|
|
end function
|
|
|
|
|
|
|
|
sub rebuildURL(captions as boolean)
|
|
|
|
playBackBuffer = -5
|
|
|
|
|
|
|
|
video = m.scene.focusedChild
|
|
|
|
video.control = "pause"
|
|
|
|
|
|
|
|
tmpParams = video.transcodeParams
|
|
|
|
if captions = false then
|
|
|
|
tmpParams.delete("SubtitleStreamIndex")
|
|
|
|
else
|
|
|
|
if video.Subtitles[video.SelectedSubtitle] <> invalid then
|
|
|
|
tmpParams.addreplace("SubtitleStreamIndex", int(video.Subtitles[video.SelectedSubtitle].Index))
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
if video.isTranscoded then
|
|
|
|
deleteTranscode(video.PlaySessionId)
|
|
|
|
end if
|
2020-05-31 13:46:33 +00:00
|
|
|
video.PlaySessionId = ItemGetPlaybackInfo(video.id, int(video.position) + playBackBuffer).PlaySessionId
|
2020-03-28 20:04:57 +00:00
|
|
|
tmpParams.PlaySessionId = video.PlaySessionId
|
2020-03-11 03:50:47 +00:00
|
|
|
video.transcodeParams = tmpParams
|
|
|
|
|
|
|
|
if video.directPlaySupported and video.decodeAudioSupported and not captions then
|
|
|
|
'Captions are off and we do not need to transcode video or audo
|
|
|
|
base = Substitute("Videos/{0}/stream", video.id)
|
|
|
|
params = {
|
|
|
|
"Static": "true",
|
|
|
|
"Container": video.container
|
|
|
|
"PlaySessionId": video.PlaySessionId
|
|
|
|
}
|
|
|
|
video.isTranscoded = false
|
|
|
|
video.content.streamformat = video.container
|
|
|
|
else
|
|
|
|
'Captions are on or we need to transcode for any other reason
|
|
|
|
video.content.streamformat = "hls"
|
|
|
|
base = Substitute("Videos/{0}/master.m3u8", video.id)
|
|
|
|
video.isTranscoded = true
|
|
|
|
params = video.transcodeParams
|
|
|
|
end if
|
|
|
|
|
|
|
|
video.content.url = buildURL(base, params)
|
2020-04-29 16:26:12 +00:00
|
|
|
video.content.PlayStart = int(video.position + playBackBuffer)
|
2020-03-11 03:50:47 +00:00
|
|
|
video.control = "play"
|
|
|
|
end sub
|