Skip to content

Commit 09045c3

Browse files
committed
Change subtitle visibility to follow Roku
Subtitle now follows Roku config Subtitle now updates immediately when changing languages
1 parent 0bcb779 commit 09045c3

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

components/JFVideo.brs

+15-8
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,33 @@ sub init()
3232

3333
'Captions
3434
m.captionGroup = m.top.findNode("captionGroup")
35-
for i = 1 to 9
36-
m.captionGroup.appendChild(createObject("roSGNode", "LayoutGroup"))
37-
end for
35+
m.captionGroup.createchildren(9, "LayoutGroup")
3836
m.captionTask = createObject("roSGNode", "captionTask")
3937
m.captionTask.observeField("currentCaption", "updateCaption")
40-
m.top.observeField("captionVisible", "toggleCaption")
4138
m.top.observeField("currentSubtitleTrack", "loadCaption")
39+
m.top.observeField("globalCaptionMode", "toggleCaption")
40+
m.top.suppressCaptions = True
41+
toggleCaption()
4242
end sub
4343

44+
4445
sub loadCaption()
4546
m.captionTask.url = m.top.currentSubtitleTrack
4647
end sub
4748

4849
sub toggleCaption()
49-
m.captionGroup.visible = m.top.captionVisible
50+
m.captionTask.playerState = m.top.state + m.top.globalCaptionMode
51+
if m.top.globalCaptionMode = "On"
52+
m.captionTask.playerState = m.captionTask.playerState + "Wait"
53+
m.captionGroup.visible = true
54+
else
55+
m.captionGroup.visible = false
56+
end if
5057
end sub
5158

5259
sub updateCaption ()
53-
m.captionGroup.replaceChildren(m.captionTask.currentCaption, 0)
60+
m.captionGroup.removeChildrenindex(9, 0)
61+
m.captionGroup.appendChildren(m.captionTask.currentCaption)
5462
end sub
5563

5664
' Event handler for when video content field changes
@@ -125,7 +133,7 @@ end sub
125133
'
126134
' When Video Player state changes
127135
sub onState(msg)
128-
m.captionTask.playerState = m.top.state
136+
m.captionTask.playerState = m.top.state + m.top.globalCaptionMode
129137
' When buffering, start timer to monitor buffering process
130138
if m.top.state = "buffering" and m.bufferCheckTimer <> invalid
131139

@@ -149,7 +157,6 @@ sub onState(msg)
149157
m.top.control = "stop"
150158
m.top.backPressed = true
151159
else if m.top.state = "playing"
152-
153160
' Check if next episde is available
154161
if isValid(m.top.showID)
155162
if m.top.showID <> "" and not m.checkedForNextEpisode and m.top.content.contenttype = 4

components/captionTask.brs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sub init()
22
m.top.observeField("url", "fetchCaption")
3-
m.top.currentCaption = CreateObject("roArray", 9, true)
3+
m.top.currentCaption = []
44
m.top.currentPos = 0
55

66
m.captionTimer = m.top.findNode("captionTimer")
@@ -29,16 +29,13 @@ sub fetchFont()
2929
m.font = "font:LargeBoldSystemFont"
3030
end if
3131
else
32-
?"font exists"
3332
m.font.uri = fontlist[0]
34-
?m.font.uri
3533
m.font.size = 60
3634
end if
3735
end sub
3836

39-
40-
4137
sub fetchCaption()
38+
m.captionTimer.control = "stop"
4239
re = CreateObject("roRegex", "(http.*?\.vtt)", "s")
4340
url = re.match(m.top.url)[0]
4441
if url <> invalid
@@ -77,8 +74,8 @@ end function
7774

7875

7976
sub updateCaption ()
80-
' Stop updating captions if the video isn't playing
81-
if m.top.playerState = "playing"
77+
m.top.currentCaption = []
78+
if m.top.playerState = "playingOn"
8279
m.top.currentPos = m.top.currentPos + 100
8380
texts = []
8481
for each entry in m.captionList
@@ -102,6 +99,10 @@ sub updateCaption ()
10299
lglist[8].getchild(q).color = &HFFFFFFFF
103100
end for
104101
m.top.currentCaption = lglist
102+
else if m.top.playerState = "playingOnWait"
103+
m.top.playerState = "playingOn"
104+
else
105+
m.top.currentCaption = []
105106
end if
106107
end sub
107108

source/utils/Subtitles.brs

+7-7
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ end function
7676
function setupSubtitle(video, subtitles, subtitle_idx = -1) as integer
7777
if subtitle_idx = -1
7878
' If we are not using text-based subtitles, turn them off
79-
' Turn captions on by default
80-
video.captionVisible = True
8179
return -1
8280
end if
8381

@@ -88,10 +86,12 @@ function setupSubtitle(video, subtitles, subtitle_idx = -1) as integer
8886

8987
if selectedSubtitle.IsEncoded
9088
' With encoded subtitles, turn off captions
91-
video.captionVisible = False
89+
?"Check2"
90+
91+
video.globalCaptionMode = "Off"
9292
else
9393
' If this is a text-based subtitle, set relevant settings for roku captions
94-
video.captionVisible = True
94+
video.globalCaptionMode = "On"
9595
video.subtitleTrack = video.availableSubtitleTracks[availSubtitleTrackIdx(video, subtitleSelIdx)].TrackName
9696
end if
9797

@@ -166,9 +166,8 @@ sub changeSubtitleDuringPlayback(newid)
166166
video.control = "play"
167167
else
168168
' Switching from text to text (or none to text) does not require stopping playback
169+
video.globalCaptionMode = "On"
169170
video.subtitleTrack = video.availableSubtitleTracks[availSubtitleTrackIdx(video, newid)].TrackName
170-
video.captionVisible = True
171-
172171
end if
173172

174173
video.SelectedSubtitle = newid
@@ -179,7 +178,8 @@ sub turnoffSubtitles()
179178
video = m.scene.focusedChild.focusedChild
180179
current = video.SelectedSubtitle
181180
video.SelectedSubtitle = -1
182-
video.captionVisible = False
181+
?"Check3"
182+
video.globalCaptionMode = "Off"
183183
m.device.EnableAppFocusEvent(false)
184184
' Check if Enoded subtitles are being displayed, and turn off
185185
if current > -1 and video.Subtitles[current].IsEncoded

0 commit comments

Comments
 (0)