Full screen hint (#264)

This commit is contained in:
Brahim Hadriche authored and GitHub committed 2024-01-11 14:56:41 -05:00
1 parent 7796c63291
commit e6302e48fe
3 files changed
+63 -1

No files matched your search

@@ -11,6 +11,10 @@ import "pkg:/source/utils/Logging.bs"
function Init()
SetPlayerStyle()
SetupAnimation()
m.fullScreenHint = m.top.findNode("fullScreenHint")
m.fullScreenHintLabel = m.top.findNode("fullScreenHintLabel")
m.fullScreenHintTimer = m.top.findNode("fullScreenHintTimer")
m.fullScreenHintTimer.ObserveField("fire", FuncName(OnFullScreenHintTimer))
' videoPlayingSuccess indicates if we started playing a video successfully
' We use it to detect if we should try another link for a video, or if another error
@@ -33,14 +37,20 @@ function Init()
end function
function OnNodeReady()
rect = m.container.fullscreen ? m.top.maxRect : m.top.minRect
minRect = m.top.minRect
rect = m.container.fullscreen ? m.top.maxRect : minRect
m.top.width = rect.width
m.top.height = rect.height
m.top.translation = [rect.x, rect.y]
m.fullScreenHint.width = minRect.width
m.fullScreenHintLabel.width = minRect.width
m.fullScreenHint.translation = [0, minRect.height - m.fullScreenHint.height]
' TODO:P2 show a loading spinner if video is loading minimized
m.top.enableUI = m.container.fullscreen
m.top.showFullScreenHint = not m.container.fullscreen
m.container.observeFieldScoped("fullscreen", FuncName(OnFullScreenChange))
m.top.ObserveField("state", FuncName(OnVideoPlayerStateChange))
@@ -319,6 +329,34 @@ function OnFullScreenChange()
m.minimizeAnimation.control = "start"
m.top.enableUI = m.container.fullscreen
m.top.showFullScreenHint = not m.container.fullscreen
SponsorBlock.SetVisible(m.notifications, m.container.fullscreen)
end function
function OnShowFullScreenHint() as void
m.fullScreenHintTimer.control = "stop"
if m.container.fullscreen
m.fullScreenHint.visible = false
return
end if
if m.top.showFullScreenHint
' Take 1 second until the shrink animation finishes to show the hint
m.fullScreenHintTimer.duration = 1
else
' Wait 5 seconds then hide the hint
m.fullScreenHintTimer.duration = 5
end if
m.fullScreenHintTimer.control = "start"
end function
function OnFullScreenHintTimer()
showFullScreenHint = m.top.showFullScreenHint
m.fullScreenHint.visible = showFullScreenHint
if showFullScreenHint
m.top.showFullScreenHint = false
end if
end function
@@ -10,6 +10,7 @@
<field id="minRect" type="rect2D" value="[834,460,426,240]" />
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
<field id="chapter" type="string" alias="chapterLabel.text" />
<field id="showFullScreenHint" type="boolean" alwaysNotify="true" onChange="OnShowFullScreenHint" />
<function name="PlayWithContent" />
<function name="Close" />
</interface>
@@ -43,5 +44,24 @@
key="[0.0, 0.5, 1.0]"
fieldToInterp="VideoPlayer.translation" />
</Animation>
<Rectangle
id="fullScreenHint"
height="26"
color="0x000000"
opacity="0.8"
visible="false">
<Label
id="fullScreenHintLabel"
text="Press Options (*) for full screen"
height="26"
color="0xFFFFFF"
horizAlign="center"
vertAlign="center"
font="font:SmallestSystemFont"
/>
<Timer
id="fullScreenHintTimer"
duration="5" />
</Rectangle>
</children>
</component>