dev player loading indicator

This commit is contained in:
Brahim Hadriche committed 2024-06-28 16:29:30 -04:00
1 parent 967d1840d0
commit c1a7765944
2 files changed
+82 -20

No files matched your search

@@ -17,29 +17,14 @@ function Init()
httpAgent.AddHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0") httpAgent.AddHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0")
m.clock = m.top.findNode("Clock") m.clock = m.top.findNode("Clock")
m.titleLabel = m.top.findNode("TitleLabel") m.titleLabel = m.top.findNode("TitleLabel")
m.secondaryTitleLabel = m.top.findNode("SecondaryTitleLabel") m.secondaryTitleLabel = m.top.findNode("SecondaryTitleLabel")
m.previousButton = m.top.findNode("PreviousButton") m.previousButton = m.top.findNode("PreviousButton")
m.playButton = m.top.findNode("PlayButton") m.playButton = m.top.findNode("PlayButton")
m.nextButton = m.top.findNode("NextButton") m.nextButton = m.top.findNode("NextButton")
m.minimizeButton = m.top.findNode("MinimizeButton") m.minimizeButton = m.top.findNode("MinimizeButton")
DisposableObserveFieldScoped(m.playButton, "buttonSelected", FuncName(OnPlayButtonSelected)) SetupLoadingSpinner()
DisposableObserveFieldScoped(m.minimizeButton, "buttonSelected", FuncName(OnMinimizeButtonSelected))
DisposableObserveField(m.top, "state", FuncName(OnPlayerStateChange))
SetNavigation(m.previousButton, "right", m.playButton)
SetNavigation(m.playButton, "right", m.nextButton)
SetNavigation(m.nextButton, "right", m.minimizeButton)
SetNavigation(m.playButton, "right", m.minimizeButton)
SetNavigation(m.minimizeButton, "left", m.nextButton)
SetNavigation(m.minimizeButton, "left", m.playButton)
SetNavigation(m.nextButton, "left", m.playButton)
SetNavigation(m.playButton, "left", m.previousButton)
end function end function
function OnNodeReady() function OnNodeReady()
@@ -51,7 +36,22 @@ function OnNodeReady()
OnHasNextChange() OnHasNextChange()
DisposableObserveFieldScoped(m.previousButton, "buttonSelected", FuncName(OnPreviousButtonSelected)) DisposableObserveFieldScoped(m.previousButton, "buttonSelected", FuncName(OnPreviousButtonSelected))
DisposableObserveFieldScoped(m.playButton, "buttonSelected", FuncName(OnPlayButtonSelected))
DisposableObserveFieldScoped(m.nextButton, "buttonSelected", FuncName(OnNextButtonSelected)) DisposableObserveFieldScoped(m.nextButton, "buttonSelected", FuncName(OnNextButtonSelected))
DisposableObserveFieldScoped(m.minimizeButton, "buttonSelected", FuncName(OnMinimizeButtonSelected))
DisposableObserveField(m.top, "state", FuncName(OnPlayerStateChange))
DisposableObserveField(m.top, "bufferingStatus", FuncName(OnBufferingStatusChange))
SetNavigation(m.previousButton, "right", m.playButton)
SetNavigation(m.playButton, "right", m.nextButton)
SetNavigation(m.nextButton, "right", m.minimizeButton)
SetNavigation(m.playButton, "right", m.minimizeButton)
SetNavigation(m.minimizeButton, "left", m.nextButton)
SetNavigation(m.minimizeButton, "left", m.playButton)
SetNavigation(m.nextButton, "left", m.playButton)
SetNavigation(m.playButton, "left", m.previousButton)
end function end function
function OnFocusChange() as void function OnFocusChange() as void
@@ -86,6 +86,11 @@ function StartVideoContentTask(videoContentNode as object)
m.top.content = videoContentNode m.top.content = videoContentNode
m.loadingLabel.text = "Loading"
m.loadingPercentLabel.text = ""
m.loadingSpinner.visible = true
m.loadingSpinner.control = "start"
m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTaskDev, { m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTaskDev, {
titleLabel: m.titleLabel titleLabel: m.titleLabel
secondaryTitleLabel: m.secondaryTitleLabel secondaryTitleLabel: m.secondaryTitleLabel
@@ -188,13 +193,50 @@ function OnPlayerStateChange()
else if state = "paused" else if state = "paused"
m.playButton.toggleState = true ' Play icon m.playButton.toggleState = true ' Play icon
end if end if
if state = "buffering"
m.loadingLabel.text = "Buffering"
m.loadingSpinner.control = "start"
m.loadingSpinner.visible = true
else
m.loadingSpinner.control = "stop"
m.loadingSpinner.visible = false
end if
end function
function OnBufferingStatusChange() as void
bufferingStatus = m.top.bufferingStatus
if bufferingStatus = invalid
return
end if
m.loadingPercentLabel.text = `${bufferingStatus.percentage}%`
end function end function
function OnDispose() function OnDispose()
m.fullScreenHintTimer.control = "stop"
m.loadingSpinner.control = "stop"
m.clock.dispose = true m.clock.dispose = true
DisposeObservers() DisposeObservers()
end function end function
function SetupLoadingSpinner()
m.loadingSpinner = m.top.findNode("LoadingSpinner")
poster = m.loadingSpinner.poster
size = 150
poster.width = size
poster.height = size
centerx = (1280 - size) / 2
centery = (720 - size) / 2
m.loadingSpinner.translation = [centerx, centery]
poster.opacity = 0.8
poster.uri = "pkg:/images/spinner.png"
m.loadingLabel = m.loadingSpinner.findNode("LoadingLabel")
m.loadingPercentLabel = m.loadingSpinner.findNode("LoadingPercentLabel")
end function
function SetupMinimizeAnimation() function SetupMinimizeAnimation()
m.fullScreenHint = m.top.findNode("fullScreenHint") m.fullScreenHint = m.top.findNode("fullScreenHint")
m.fullScreenHintLabel = m.top.findNode("fullScreenHintLabel") m.fullScreenHintLabel = m.top.findNode("fullScreenHintLabel")
@@ -30,9 +30,9 @@
<Group id="TopUI"> <Group id="TopUI">
<!-- <!--
TODO:P2 once VideoPlayerDev replaces VideoPlayer, the clock can TODO:P2 once VideoPlayerDev replaces VideoPlayer, the clock can
be removed to reuse the Clock from MainScene be removed to reuse the Clock from MainScene
--> -->
<Clock id="Clock" /> <Clock id="Clock" />
<LayoutGroup <LayoutGroup
itemSpacings="[5]" itemSpacings="[5]"
@@ -49,7 +49,7 @@
wrap="true" /> wrap="true" />
</LayoutGroup> </LayoutGroup>
</Group> </Group>
<Group> <Group id="Buttons">
<LayoutGroup <LayoutGroup
layoutDirection="horiz" layoutDirection="horiz"
horizAlignment="left" horizAlignment="left"
@@ -72,6 +72,26 @@
iconUri="pkg:/images/icons/player/minimize.png" /> iconUri="pkg:/images/icons/player/minimize.png" />
</LayoutGroup> </LayoutGroup>
</Group> </Group>
<Group>
<BusySpinner
id="LoadingSpinner"
spinInterval="1"
visible="false">
<Label
id="LoadingPercentLabel"
horizAlign="center"
vertAlign="center"
width="150"
height="150"
font="font:SmallestSystemFont" />
<Label
id="LoadingLabel"
width="150"
horizAlign="center"
translation="[0,150]"
font="font:SmallestSystemFont" />
</BusySpinner>
</Group>
</Group> </Group>
<Animation id="minimizeAnimation" duration="0.3" optional="true"> <Animation id="minimizeAnimation" duration="0.3" optional="true">