Change subtitle visibility to follow Roku

Subtitle now follows Roku config

Subtitle now updates immediately when changing languages
This commit is contained in:
Jinho Kim 2023-02-01 22:16:25 -05:00
parent 0bcb779507
commit 09045c32c8
3 changed files with 30 additions and 22 deletions

View File

@ -32,25 +32,33 @@ sub init()
'Captions
m.captionGroup = m.top.findNode("captionGroup")
for i = 1 to 9
m.captionGroup.appendChild(createObject("roSGNode", "LayoutGroup"))
end for
m.captionGroup.createchildren(9, "LayoutGroup")
m.captionTask = createObject("roSGNode", "captionTask")
m.captionTask.observeField("currentCaption", "updateCaption")
m.top.observeField("captionVisible", "toggleCaption")
m.top.observeField("currentSubtitleTrack", "loadCaption")
m.top.observeField("globalCaptionMode", "toggleCaption")
m.top.suppressCaptions = True
toggleCaption()
end sub
sub loadCaption()
m.captionTask.url = m.top.currentSubtitleTrack
end sub
sub toggleCaption()
m.captionGroup.visible = m.top.captionVisible
m.captionTask.playerState = m.top.state + m.top.globalCaptionMode
if m.top.globalCaptionMode = "On"
m.captionTask.playerState = m.captionTask.playerState + "Wait"
m.captionGroup.visible = true
else
m.captionGroup.visible = false
end if
end sub
sub updateCaption ()
m.captionGroup.replaceChildren(m.captionTask.currentCaption, 0)
m.captionGroup.removeChildrenindex(9, 0)
m.captionGroup.appendChildren(m.captionTask.currentCaption)
end sub
' Event handler for when video content field changes
@ -125,7 +133,7 @@ end sub
'
' When Video Player state changes
sub onState(msg)
m.captionTask.playerState = m.top.state
m.captionTask.playerState = m.top.state + m.top.globalCaptionMode
' When buffering, start timer to monitor buffering process
if m.top.state = "buffering" and m.bufferCheckTimer <> invalid
@ -149,7 +157,6 @@ sub onState(msg)
m.top.control = "stop"
m.top.backPressed = true
else if m.top.state = "playing"
' Check if next episde is available
if isValid(m.top.showID)
if m.top.showID <> "" and not m.checkedForNextEpisode and m.top.content.contenttype = 4

View File

@ -1,6 +1,6 @@
sub init()
m.top.observeField("url", "fetchCaption")
m.top.currentCaption = CreateObject("roArray", 9, true)
m.top.currentCaption = []
m.top.currentPos = 0
m.captionTimer = m.top.findNode("captionTimer")
@ -29,16 +29,13 @@ sub fetchFont()
m.font = "font:LargeBoldSystemFont"
end if
else
?"font exists"
m.font.uri = fontlist[0]
?m.font.uri
m.font.size = 60
end if
end sub
sub fetchCaption()
m.captionTimer.control = "stop"
re = CreateObject("roRegex", "(http.*?\.vtt)", "s")
url = re.match(m.top.url)[0]
if url <> invalid
@ -77,8 +74,8 @@ end function
sub updateCaption ()
' Stop updating captions if the video isn't playing
if m.top.playerState = "playing"
m.top.currentCaption = []
if m.top.playerState = "playingOn"
m.top.currentPos = m.top.currentPos + 100
texts = []
for each entry in m.captionList
@ -102,6 +99,10 @@ sub updateCaption ()
lglist[8].getchild(q).color = &HFFFFFFFF
end for
m.top.currentCaption = lglist
else if m.top.playerState = "playingOnWait"
m.top.playerState = "playingOn"
else
m.top.currentCaption = []
end if
end sub

View File

@ -76,8 +76,6 @@ end function
function setupSubtitle(video, subtitles, subtitle_idx = -1) as integer
if subtitle_idx = -1
' If we are not using text-based subtitles, turn them off
' Turn captions on by default
video.captionVisible = True
return -1
end if
@ -88,10 +86,12 @@ function setupSubtitle(video, subtitles, subtitle_idx = -1) as integer
if selectedSubtitle.IsEncoded
' With encoded subtitles, turn off captions
video.captionVisible = False
?"Check2"
video.globalCaptionMode = "Off"
else
' If this is a text-based subtitle, set relevant settings for roku captions
video.captionVisible = True
video.globalCaptionMode = "On"
video.subtitleTrack = video.availableSubtitleTracks[availSubtitleTrackIdx(video, subtitleSelIdx)].TrackName
end if
@ -166,9 +166,8 @@ sub changeSubtitleDuringPlayback(newid)
video.control = "play"
else
' Switching from text to text (or none to text) does not require stopping playback
video.globalCaptionMode = "On"
video.subtitleTrack = video.availableSubtitleTracks[availSubtitleTrackIdx(video, newid)].TrackName
video.captionVisible = True
end if
video.SelectedSubtitle = newid
@ -179,7 +178,8 @@ sub turnoffSubtitles()
video = m.scene.focusedChild.focusedChild
current = video.SelectedSubtitle
video.SelectedSubtitle = -1
video.captionVisible = False
?"Check3"
video.globalCaptionMode = "Off"
m.device.EnableAppFocusEvent(false)
' Check if Enoded subtitles are being displayed, and turn off
if current > -1 and video.Subtitles[current].IsEncoded