1
1
sub init ()
2
2
m .top .observeField ("url" , "fetchCaption" )
3
- m .top .currentCaption = []
3
+ m .top .currentCaption = CreateObject ( " roArray " , 9 , true )
4
4
m .top .currentPos = 0
5
5
6
6
m .captionTimer = m .top .findNode ("captionTimer" )
7
7
m .captionTimer .ObserveField ("fire" , "updateCaption" )
8
8
9
9
m .captionList = []
10
10
m .reader = createObject ("roUrlTransfer " )
11
-
12
11
m .font = CreateObject ("roSGNode " , "Font" )
13
- m .font .uri = "pkg:/components/fonts/noto.otf"
14
- m .font .size = 50
15
- ' m.font = "font:LargeSystemFont"
12
+ fetchFont ()
16
13
end sub
17
14
15
+
16
+ sub fetchFont ()
17
+ fs = CreateObject ("roFileSystem " )
18
+ fontlist = fs .Find ("tmp:/" , ".*\.(otf|ttf)" )
19
+ if fontlist .count () = 0
20
+ re = CreateObject ("roRegex " , "Name.:.(.*?).,.Size" , "s" )
21
+ m .filename = APIRequest ("FallbackFont/Fonts" ).GetToString ()
22
+ m .filename = re .match (m .filename )
23
+ if m .filename .count () <> 0
24
+ m .filename = m .filename [1 ]
25
+ APIRequest ("FallbackFont/Fonts/" + m .filename ).gettofile ("tmp:/" + m .filename )
26
+ m .font .uri = "tmp:/" + m .filename
27
+ m .font .size = 60
28
+ else
29
+ m .font = "font:LargeBoldSystemFont"
30
+ end if
31
+ else
32
+ ?"font exists"
33
+ m .font .uri = fontlist [0 ]
34
+ ?m .font .uri
35
+ m .font .size = 60
36
+ end if
37
+ end sub
38
+
39
+
40
+
18
41
sub fetchCaption ()
19
42
re = CreateObject ("roRegex " , "(http.*?\.vtt)" , "s" )
20
43
url = re .match (m .top .url )[0 ]
@@ -28,22 +51,58 @@ sub fetchCaption()
28
51
end if
29
52
end sub
30
53
54
+ function newlabel (txt ):
55
+ label = CreateObject ("roSGNode " , "Label" )
56
+ label .text = txt
57
+ label .font = m .font
58
+ label .color = & H000000FF
59
+ label .height = 108
60
+ return label
61
+ end function
62
+
63
+ function newlayout (labels )
64
+ invis = CreateObject ("roSGNode " , "Label" )
65
+ invis .visible = False
66
+ l = labels .count ()
67
+ newlg = CreateObject ("roSGNode " , "LayoutGroup" )
68
+ for i = 0 to 7 - l
69
+ newlg .appendchild (invis .clone (True ))
70
+ end for
71
+ newlg .appendchildren (labels )
72
+ newlg .horizalignment = "center"
73
+ newlg .vertalignment = "bottom"
74
+
75
+ return newlg
76
+ end function
77
+
78
+
31
79
sub updateCaption ()
32
80
' Stop updating captions if the video isn't playing
33
81
if m .top .playerState = "playing"
34
82
m .top .currentPos = m .top .currentPos + 100
35
- tmp = []
83
+ texts = []
36
84
for each entry in m .captionList
37
85
if entry ["start" ] <= m .top .currentPos and m .top .currentPos <= entry ["end" ]
38
- label = CreateObject ("roSGNode " , "Label" )
39
- label .text = entry ["text" ]
40
- label .font = m .font
41
- tmp .push (label )
86
+ texts .push (entry ["text" ])
42
87
end if
43
88
end for
44
- m .top .currentCaption = tmp
89
+ labels = []
90
+ for each text in texts
91
+ labels .push (newlabel (text ))
92
+ end for
93
+ lg = newlayout (labels )
94
+ lglist = []
95
+ coords = [[- 1 , - 1 ], [- 1 , 0 ], [- 1 , 1 ], [0 , - 1 ], [0 , 1 ], [1 , - 1 ], [1 , 0 ], [1 , 1 ], [0 , 0 ]]
96
+ for p = 0 to 8
97
+ lgg = lg .clone (True )
98
+ lgg .translation = [coords [p ][0 ] * 5 , coords [p ][1 ] * 5 ]
99
+ lglist .push (lgg )
100
+ end for
101
+ for q = 0 to 7
102
+ lglist [8 ].getchild (q ).color = & HFFFFFFFF
103
+ end for
104
+ m .top .currentCaption = lglist
45
105
end if
46
- ' end if
47
106
end sub
48
107
49
108
function ms (t ) as integer
0 commit comments