Skip to content

Commit ac974f9

Browse files
committed
Update code docs
1 parent 1c87fc9 commit ac974f9

5 files changed

Lines changed: 138 additions & 30 deletions

File tree

docs/components_captionTask.bs.html

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
m.top.observeField("url", "fetchCaption")
1111
m.top.currentCaption = []
1212
m.top.currentPos = 0
13+
m.lastCaptionTexts = invalid
1314

1415
m.captionTimer = m.top.findNode("captionTimer")
1516
m.captionTimer.ObserveField("fire", "updateCaption")
@@ -31,6 +32,19 @@
3132
m.textOpac = m.percentageDict[deviceInfo.GetCaptionsOption("Text/Opacity")]
3233
m.bgColor = m.bgColorDict[deviceInfo.GetCaptionsOption("Background/Color")]
3334
m.bgOpac = m.percentageDict[deviceInfo.GetCaptionsOption("Background/Opacity")]
35+
36+
' Validate fontSize - fallback to default if invalid
37+
if not isValid(m.fontSize) or m.fontSize <= 0
38+
m.fontSize = m.fontSizeDict["Default"]
39+
m.log.warn("Invalid font size from device settings, using default", m.fontSize)
40+
end if
41+
42+
' Validate text opacity - ensure visibility if set to 0 (Off)
43+
if not isValid(m.textOpac) or m.textOpac <= 0
44+
m.textOpac = m.percentageDict["Default"]
45+
m.log.warn("Text opacity is 0 or invalid, using default for visibility", m.textOpac)
46+
end if
47+
3448
setFont()
3549
end sub
3650

@@ -45,8 +59,20 @@
4559
end if
4660
end sub
4761

62+
function arraysEqual(arr1, arr2) as boolean
63+
if not isValid(arr1) and not isValid(arr2) then return true
64+
if not isValid(arr1) or not isValid(arr2) then return false
65+
if arr1.count() <> arr2.count() then return false
66+
67+
for i = 0 to arr1.count() - 1
68+
if arr1[i] <> arr2[i] then return false
69+
end for
70+
71+
return true
72+
end function
73+
4874
sub fetchCaption()
49-
m.log.debug("start fetchCaption()")
75+
m.log.debug("Start fetchCaption()", m.top.url)
5076
m.captionTimer.control = "stop"
5177
re = CreateObject("roRegex", "(http.*?\.vtt)", "s")
5278
url = re.match(m.top.url)[0]
@@ -56,16 +82,30 @@
5682
m.reader.setUrl(url)
5783
m.reader.setMessagePort(port)
5884
if m.reader.AsyncGetToString()
59-
msg = port.waitMessage(0)
60-
if type(msg) = "roUrlEvent"
61-
m.captionList = parseVTT(msg.GetString())
62-
m.captionTimer.control = "start"
85+
' Wait for response with 10 second timeout to prevent infinite blocking
86+
msg = port.waitMessage(10000)
87+
if isValid(msg) and type(msg) = "roUrlEvent"
88+
responseCode = msg.GetResponseCode()
89+
if responseCode = 200
90+
vttContent = msg.GetString()
91+
m.log.debug("VTT content received, length:", vttContent.len())
92+
m.captionList = parseVTT(vttContent)
93+
m.log.info("Parsed", m.captionList.count(), "caption entries")
94+
m.captionTimer.control = "start"
95+
else
96+
m.log.error("Failed to fetch captions. HTTP response code:", responseCode)
97+
end if
98+
else
99+
m.log.error("Timeout or invalid response when fetching captions")
63100
end if
101+
else
102+
m.log.error("Failed to initiate caption download")
64103
end if
65104
else
105+
m.log.warn("No valid VTT URL found in:", m.top.url)
66106
m.captionTimer.control = "stop"
67107
end if
68-
m.log.debug("end fetchCaption()", url)
108+
m.log.debug("End fetchCaption()")
69109
end sub
70110

71111
function newlabel(txt)
@@ -107,7 +147,6 @@
107147

108148

109149
sub updateCaption()
110-
m.top.currentCaption = []
111150
if LCase(m.top.playerState) = "playingon"
112151
m.top.currentPos = m.top.currentPos + 100
113152
texts = []
@@ -117,15 +156,27 @@
117156
texts.push(t)
118157
end if
119158
end for
120-
labels = []
121-
for each text in texts
122-
labels.push(newlabel (text))
123-
end for
124-
lines = newLayoutGroup(labels)
125-
rect = newRect(lines)
126-
m.top.currentCaption = [rect, lines]
159+
160+
' Only update captions if content has changed
161+
if not isValid(m.lastCaptionTexts) or not arraysEqual(texts, m.lastCaptionTexts)
162+
m.lastCaptionTexts = texts
163+
m.top.currentCaption = []
164+
165+
if texts.count() > 0
166+
labels = []
167+
for each text in texts
168+
labels.push(newlabel(text))
169+
end for
170+
lines = newLayoutGroup(labels)
171+
rect = newRect(lines)
172+
m.top.currentCaption = [rect, lines]
173+
else
174+
' Clear captions when no text should be displayed
175+
m.top.currentCaption = []
176+
end if
177+
end if
127178
else if LCase(m.top.playerState.right(1)) = "w"
128-
m.top.playerState = m.top.playerState.left(len (m.top.playerState) - 1)
179+
m.top.playerState = m.top.playerState.left(len(m.top.playerState) - 1)
129180
end if
130181
end sub
131182

docs/components_video_VideoPlayerView.bs.html

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,43 @@
275275
end if
276276
end sub
277277

278+
' Determines if custom subtitles should be used for the current selection
279+
' Custom subtitles should only be used for external subtitles when the user has enabled the setting
280+
function shouldUseCustomSubtitlesForCurrentSelection() as boolean
281+
' First check if the user has enabled custom subtitles at all
282+
if not m.global.session.user.settings["playback.subs.custom"]
283+
m.log.debug("Custom subtitles disabled by user setting")
284+
return false
285+
end if
286+
287+
' If no subtitle is currently selected, no need for custom subtitles
288+
if not isValid(m.top.selectedSubtitle) or m.top.selectedSubtitle = -1
289+
m.log.debug("No subtitle selected", m.top.selectedSubtitle)
290+
return false
291+
end if
292+
293+
' Find the selected subtitle in the fullSubtitleData
294+
selectedSubtitle = invalid
295+
if isValid(m.top.fullSubtitleData)
296+
for each subtitle in m.top.fullSubtitleData
297+
if subtitle.Index = m.top.selectedSubtitle
298+
selectedSubtitle = subtitle
299+
exit for
300+
end if
301+
end for
302+
end if
303+
304+
' If we found the selected subtitle and it's external, use custom subtitles
305+
if isValid(selectedSubtitle) and isValid(selectedSubtitle.IsExternal)
306+
m.log.debug("Subtitle found", selectedSubtitle.IsExternal, selectedSubtitle.Index)
307+
return selectedSubtitle.IsExternal
308+
end if
309+
310+
m.log.debug("Selected subtitle not found in fullSubtitleData or invalid IsExternal flag")
311+
' Default to false (use native Roku subtitles)
312+
return false
313+
end function
314+
278315
' Only setup caption items if captions are allowed
279316
sub onAllowCaptionsChange()
280317
if not m.top.allowCaptions then return
@@ -287,17 +324,13 @@
287324
m.top.observeField("subtitleTrack", "loadCaption")
288325
m.top.observeField("globalCaptionMode", "toggleCaption")
289326

290-
if m.global.session.user.settings["playback.subs.custom"]
291-
m.top.suppressCaptions = true
292-
toggleCaption()
293-
else
294-
m.top.suppressCaptions = false
295-
end if
296327
end sub
297328

298329
' Set caption url to server subtitle track
299330
sub loadCaption()
331+
m.log.debug("loadCaption() called", m.top.subtitleTrack, m.top.suppressCaptions)
300332
if m.top.suppressCaptions
333+
m.log.debug("Setting captionTask.url", m.top.subtitleTrack)
301334
m.captionTask.url = m.top.subtitleTrack
302335
end if
303336
end sub
@@ -331,6 +364,22 @@
331364
' If previous sustitle was encoded, then we need to a video stop/start to change subtitle content
332365
if m.top.previousSubtitleWasEncoded then switchWithoutRefresh = false
333366

367+
' Update custom subtitle behavior based on new selection
368+
if m.top.allowCaptions
369+
shouldUseCustomSubtitles = shouldUseCustomSubtitlesForCurrentSelection()
370+
371+
m.log.debug("Subtitle changed", shouldUseCustomSubtitles, m.top.suppressCaptions)
372+
373+
if shouldUseCustomSubtitles <> m.top.suppressCaptions
374+
' Custom subtitle mode has changed, update it
375+
m.log.debug("Changing custom subtitle mode to", shouldUseCustomSubtitles)
376+
m.top.suppressCaptions = shouldUseCustomSubtitles
377+
if m.top.suppressCaptions
378+
toggleCaption()
379+
end if
380+
end if
381+
end if
382+
334383
if switchWithoutRefresh then return
335384

336385
' Save the current video position
@@ -460,6 +509,15 @@
460509

461510
m.top.selectedSubtitle = videoContent[0].selectedSubtitle
462511

512+
' Update custom subtitle behavior based on the selected subtitle
513+
if m.top.allowCaptions
514+
shouldUseCustomSubtitles = shouldUseCustomSubtitlesForCurrentSelection()
515+
m.top.suppressCaptions = shouldUseCustomSubtitles
516+
if m.top.suppressCaptions
517+
toggleCaption()
518+
end if
519+
end if
520+
463521
m.top.observeField("selectedSubtitle", "onSubtitleChange")
464522

465523
if isValid(m.top.audioIndex)
@@ -526,7 +584,6 @@
526584

527585
' align button with bottom right edge with 5% padding
528586
boundingRect = m.notifyButtons.localBoundingRect()
529-
print "boundingRect =", boundingRect
530587

531588
m.notifyButtons.translation = [
532589
1920 - (1920 * 0.05),
@@ -613,7 +670,7 @@
613670
'
614671
' When Video Player state changes
615672
sub onState()
616-
m.log.debug("start onState()", m.top.state)
673+
m.log.debug("start onState", m.top.state)
617674
if isValid(m.captionTask)
618675
m.captionTask.playerState = m.top.state + m.top.globalCaptionMode
619676
end if
@@ -683,15 +740,15 @@
683740
else
684741
m.log.warning("Unhandled state", m.top.state, m.playReported, m.playFinished)
685742
end if
686-
m.log.debug("end onState()", m.top.state)
743+
m.log.debug("end onState", m.top.state)
687744
end sub
688745

689746
'
690747
' Report playback to server
691748
sub ReportPlayback(state = "update" as string)
692749
if not isValid(m.top.position) then return
693750

694-
m.log.debug("start ReportPlayback()", state, int(m.top.position))
751+
m.log.debug("start ReportPlayback", state, int(m.top.position))
695752

696753
params = {
697754
"ItemId": m.top.id,
@@ -708,7 +765,7 @@
708765
end if
709766

710767
if (state = "stop" or state = "finished") and isValid(m.originalClosedCaptionState)
711-
m.log.debug("ReportPlayback() setting", m.top.globalCaptionMode, "back to", m.originalClosedCaptionState)
768+
m.log.debug("ReportPlayback setting", m.top.globalCaptionMode, "back to", m.originalClosedCaptionState)
712769
m.top.globalCaptionMode = m.originalClosedCaptionState
713770
m.originalClosedCaptionState = invalid
714771
end if
@@ -718,7 +775,7 @@
718775
playstateTask.setFields({ status: state, params: params })
719776
playstateTask.control = "RUN"
720777

721-
m.log.debug("end ReportPlayback()", state, int(m.top.position))
778+
m.log.debug("end ReportPlayback", state, int(m.top.position))
722779
end sub
723780

724781
'

docs/data/search.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/module-VideoPlayerView.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/module-captionTask.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)