Basic state machine for dev player
This commit is contained in:
1 parent
84a860cd6c
commit
27fc34338d
3 files changed
+188
-100
No files matched your search
@@ -0,0 +1,147 @@
|
|||||||
|
enum PlayerUiState
|
||||||
|
None ' None is not a valid state, but it is the default value pre-initialization
|
||||||
|
FadingIn
|
||||||
|
Visible
|
||||||
|
FadingOut
|
||||||
|
Hidden
|
||||||
|
end enum
|
||||||
|
|
||||||
|
function InitializePlayerUi()
|
||||||
|
m.top.enableUI = false
|
||||||
|
m.top.enableTrickPlay = false
|
||||||
|
|
||||||
|
FindUiNodes()
|
||||||
|
SetupLoadingSpinner()
|
||||||
|
|
||||||
|
DisposableObserveFieldScoped(m.uiFadeAnimation, "state", FuncName(OnUiFadeAnimationStateChange))
|
||||||
|
DisposableObserveField(m.hideVideoUiTimer, "fire", FuncName(OnHideVideoUiTimer))
|
||||||
|
|
||||||
|
DisposableObserveField(m.top, "playerUiState", FuncName(OnPlayerUiState))
|
||||||
|
|
||||||
|
m.top.playerUiState = PlayerUiState.Visible
|
||||||
|
end function
|
||||||
|
|
||||||
|
function FindUiNodes()
|
||||||
|
m.clock = m.top.findNode("Clock")
|
||||||
|
m.titleLabel = m.top.findNode("TitleLabel")
|
||||||
|
m.secondaryTitleLabel = m.top.findNode("SecondaryTitleLabel")
|
||||||
|
m.backgroundPoster = m.top.findNode("BackgroundPoster")
|
||||||
|
m.backgroundPosterSmall = m.top.findNode("BackgroundPosterSmall")
|
||||||
|
m.previousButton = m.top.findNode("PreviousButton")
|
||||||
|
m.playButton = m.top.findNode("PlayButton")
|
||||||
|
m.nextButton = m.top.findNode("NextButton")
|
||||||
|
m.minimizeButton = m.top.findNode("MinimizeButton")
|
||||||
|
m.trickPlayBar = m.top.findNode("TrickPlayBar")
|
||||||
|
m.videoUi = m.top.findNode("VideoUi")
|
||||||
|
m.progressTimer = m.top.findNode("ProgressTimer")
|
||||||
|
m.hideVideoUiTimer = m.top.findNode("HideVideoUiTimer")
|
||||||
|
m.uiFadeAnimation = m.top.findNode("UiFadeAnimation")
|
||||||
|
m.uiFadeOpacityInterpolator = m.top.findNode("UiFadeOpacityInterpolator")
|
||||||
|
m.loadingUi = m.top.findNode("LoadingUi")
|
||||||
|
m.loadingSpinnerBackground = m.loadingUi.findNode("LoadingSpinnerBackground")
|
||||||
|
m.loadingSpinner = m.loadingUi.findNode("LoadingSpinner")
|
||||||
|
m.loadingLabel = m.loadingSpinner.findNode("LoadingLabel")
|
||||||
|
m.loadingPercentLabel = m.loadingSpinner.findNode("LoadingPercentLabel")
|
||||||
|
end function
|
||||||
|
|
||||||
|
function SetupLoadingSpinner()
|
||||||
|
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"
|
||||||
|
|
||||||
|
size = 80
|
||||||
|
centerx = (1280 - size) / 2
|
||||||
|
centery = (720 - size) / 2
|
||||||
|
m.loadingSpinnerBackground.translation = [centerx, centery]
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnPlayerUiState()
|
||||||
|
state = m.top.playerUiState
|
||||||
|
|
||||||
|
if state = PlayerUiState.FadingIn
|
||||||
|
OnPlayerUiFadingIn()
|
||||||
|
else if state = PlayerUiState.Visible
|
||||||
|
OnPlayerUiVisible()
|
||||||
|
else if state = PlayerUiState.FadingOut
|
||||||
|
OnPlayerUiFadingOut()
|
||||||
|
else if state = PlayerUiState.Hidden
|
||||||
|
OnPlayerUiHidden()
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnPlayerUiFadingIn()
|
||||||
|
if m.top.hasFocus()
|
||||||
|
NodeSetFocus(m.playButton, true)
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.uiFadeOpacityInterpolator.reverse = false
|
||||||
|
m.uiFadeAnimation.control = "start"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnPlayerUiVisible()
|
||||||
|
if m.top.hasFocus()
|
||||||
|
NodeSetFocus(m.playButton, true)
|
||||||
|
end if
|
||||||
|
|
||||||
|
StartHideVideoUiTimer()
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnPlayerUiFadingOut()
|
||||||
|
m.uiFadeOpacityInterpolator.reverse = true
|
||||||
|
m.uiFadeAnimation.control = "start"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnPlayerUiHidden()
|
||||||
|
m.videoUi.opacity = 0
|
||||||
|
|
||||||
|
if m.top.isInFocusChain() and not m.top.hasFocus()
|
||||||
|
NodeSetFocus(m.top, false)
|
||||||
|
NodeSetFocus(m.top, true)
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function StartHideVideoUiTimer()
|
||||||
|
m.hideVideoUiTimer.control = "stop"
|
||||||
|
m.hideVideoUiTimer.control = "start"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function StopHideVideoUiTimer()
|
||||||
|
m.hideVideoUiTimer.control = "stop"
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnHideVideoUiTimer() as void
|
||||||
|
if m.top.playerUiState = PlayerUiState.Hidden
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
m.top.playerUiState = PlayerUiState.FadingOut
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnUiFadeAnimationStateChange() as void
|
||||||
|
' "stopped" Indicates that the animation has either run to completion or has been explicitly stopped.
|
||||||
|
' Since we don't stop the animation explicitly, we can assume that the animation has run to completion.
|
||||||
|
' This assumption becomes invalid if we set m.uiFadeAnimation.control = "stop"
|
||||||
|
if m.uiFadeAnimation.state <> "stopped"
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
|
||||||
|
state = m.top.playerUiState
|
||||||
|
if state = PlayerUiState.FadingIn
|
||||||
|
m.top.playerUiState = PlayerUiState.Visible
|
||||||
|
else if state = PlayerUiState.FadingOut
|
||||||
|
m.top.playerUiState = PlayerUiState.Hidden
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ShutDownPlayerUi()
|
||||||
|
m.hideVideoUiTimer.control = "stop"
|
||||||
|
m.loadingSpinner.control = "stop"
|
||||||
|
m.clock.dispose = true
|
||||||
|
end function
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import "pkg:/components/Navigation/Navigation.bs"
|
import "pkg:/components/Navigation/Navigation.bs"
|
||||||
import "pkg:/components/VideoPlayerDev/PictureInPicture.bs"
|
import "pkg:/components/VideoPlayerDev/PictureInPicture.bs"
|
||||||
|
import "pkg:/components/VideoPlayerDev/PlayerUi.bs"
|
||||||
import "pkg:/components/VideoQueue/VideoQueueUtils.bs"
|
import "pkg:/components/VideoQueue/VideoQueueUtils.bs"
|
||||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||||
@@ -12,29 +13,11 @@ import "pkg:/source/utils/StringUtils.bs"
|
|||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
function Init()
|
function Init()
|
||||||
m.top.enableUI = false
|
InitializePlayerUi()
|
||||||
m.top.enableTrickPlay = false
|
|
||||||
|
|
||||||
httpAgent = m.top.getHttpAgent()
|
httpAgent = m.top.getHttpAgent()
|
||||||
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.titleLabel = m.top.findNode("TitleLabel")
|
|
||||||
m.secondaryTitleLabel = m.top.findNode("SecondaryTitleLabel")
|
|
||||||
m.backgroundPoster = m.top.findNode("BackgroundPoster")
|
|
||||||
m.backgroundPosterSmall = m.top.findNode("BackgroundPosterSmall")
|
|
||||||
m.previousButton = m.top.findNode("PreviousButton")
|
|
||||||
m.playButton = m.top.findNode("PlayButton")
|
|
||||||
m.nextButton = m.top.findNode("NextButton")
|
|
||||||
m.minimizeButton = m.top.findNode("MinimizeButton")
|
|
||||||
m.trickPlayBar = m.top.findNode("TrickPlayBar")
|
|
||||||
m.videoUi = m.top.findNode("VideoUI")
|
|
||||||
m.progressTimer = m.top.findNode("ProgressTimer")
|
|
||||||
m.hideVideoUiTimer = m.top.findNode("HideVideoUiTimer")
|
|
||||||
m.fadeAnimation = m.top.findNode("FadeAnimation")
|
|
||||||
m.fadeOpacityInterpolator = m.top.findNode("FadeOpacityInterpolator")
|
|
||||||
|
|
||||||
SetupLoadingSpinner()
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnNodeReady()
|
function OnNodeReady()
|
||||||
@@ -54,7 +37,6 @@ function OnNodeReady()
|
|||||||
DisposableObserveField(m.top, "bufferingStatus", FuncName(OnBufferingStatusChange))
|
DisposableObserveField(m.top, "bufferingStatus", FuncName(OnBufferingStatusChange))
|
||||||
|
|
||||||
DisposableObserveField(m.progressTimer, "fire", FuncName(OnProgress))
|
DisposableObserveField(m.progressTimer, "fire", FuncName(OnProgress))
|
||||||
DisposableObserveField(m.hideVideoUiTimer, "fire", FuncName(OnHideVideoUiTimer))
|
|
||||||
|
|
||||||
SetNavigation(m.previousButton, RemoteKeys.Right, m.playButton)
|
SetNavigation(m.previousButton, RemoteKeys.Right, m.playButton)
|
||||||
SetNavigation(m.playButton, RemoteKeys.Right, m.nextButton)
|
SetNavigation(m.playButton, RemoteKeys.Right, m.nextButton)
|
||||||
@@ -160,20 +142,42 @@ function OnClose()
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function OnKeyEvent(key as string, press as boolean) as boolean
|
function OnKeyEvent(key as string, press as boolean) as boolean
|
||||||
m.hideVideoUiTimer.control = "stop"
|
if press = false
|
||||||
m.hideVideoUiTimer.control = "start"
|
return false
|
||||||
if ShowVideoUi()
|
end if
|
||||||
return true
|
|
||||||
|
state = m.top.state
|
||||||
|
uiState = m.top.playerUiState
|
||||||
|
|
||||||
|
if key = RemoteKeys.Play
|
||||||
|
if state = "paused" and uiState = PlayerUiState.Hidden
|
||||||
|
' If we pressed play and the state is paused, the player is about to resume.
|
||||||
|
' Return false to let the default behavior resume video.
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
if key = RemoteKeys.Play or key = RemoteKeys.PlayOnly
|
||||||
|
if state = "playing" and uiState = PlayerUiState.Hidden
|
||||||
|
' If we pressed play and the state is playing, the player is about to pause.
|
||||||
|
' Return false to let the default behavior pause video.
|
||||||
|
m.top.playerUiState = PlayerUiState.FadingIn
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
if uiState = PlayerUiState.Visible
|
||||||
|
StartHideVideoUiTimer()
|
||||||
|
end if
|
||||||
|
|
||||||
|
if uiState = PlayerUiState.Hidden or uiState = PlayerUiState.FadingOut
|
||||||
|
m.top.playerUiState = PlayerUiState.FadingIn
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if NavigationKeyHandler(key, press).handled
|
if NavigationKeyHandler(key, press).handled
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if press = false
|
|
||||||
return false
|
|
||||||
end if
|
|
||||||
|
|
||||||
if key = RemoteKeys.Back
|
if key = RemoteKeys.Back
|
||||||
m.videoQueue.closePlayer = true
|
m.videoQueue.closePlayer = true
|
||||||
return true
|
return true
|
||||||
@@ -264,72 +268,8 @@ function OnProgress() as void
|
|||||||
m.trickPlayBar.progress = m.top.position / duration
|
m.trickPlayBar.progress = m.top.position / duration
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnHideVideoUiTimer()
|
|
||||||
HideVideoUi()
|
|
||||||
end function
|
|
||||||
|
|
||||||
function OnDispose()
|
function OnDispose()
|
||||||
ShutDownPitctureInPicture()
|
ShutDownPitctureInPicture()
|
||||||
m.fadeAnimation.control = "stop"
|
ShutDownPlayerUi()
|
||||||
m.hideVideoUiTimer.control = "stop"
|
|
||||||
m.loadingSpinner.control = "stop"
|
|
||||||
m.clock.dispose = true
|
|
||||||
DisposeObservers()
|
DisposeObservers()
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function SetupLoadingSpinner()
|
|
||||||
m.loadingUi = m.top.findNode("LoadingUI")
|
|
||||||
m.loadingSpinnerBackground = m.loadingUi.findNode("LoadingSpinnerBackground")
|
|
||||||
m.loadingSpinner = m.loadingUi.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"
|
|
||||||
|
|
||||||
size = 80
|
|
||||||
centerx = (1280 - size) / 2
|
|
||||||
centery = (720 - size) / 2
|
|
||||||
m.loadingSpinnerBackground.translation = [centerx, centery]
|
|
||||||
|
|
||||||
m.loadingLabel = m.loadingSpinner.findNode("LoadingLabel")
|
|
||||||
m.loadingPercentLabel = m.loadingSpinner.findNode("LoadingPercentLabel")
|
|
||||||
end function
|
|
||||||
|
|
||||||
function ShowVideoUi() as boolean
|
|
||||||
if m.fadeAnimation.state = "stopped"
|
|
||||||
if m.videoUi.opacity = 1
|
|
||||||
return false
|
|
||||||
end if
|
|
||||||
end if
|
|
||||||
|
|
||||||
m.fadeAnimation.control = "stop"
|
|
||||||
m.fadeOpacityInterpolator.reverse = false
|
|
||||||
m.fadeAnimation.control = "start"
|
|
||||||
|
|
||||||
if m.top.hasFocus()
|
|
||||||
NodeSetFocus(m.playButton, true)
|
|
||||||
end if
|
|
||||||
|
|
||||||
return true
|
|
||||||
end function
|
|
||||||
|
|
||||||
function HideVideoUi() as void
|
|
||||||
if m.fadeAnimation.state = "stopped"
|
|
||||||
if m.videoUi.opacity = 0
|
|
||||||
return
|
|
||||||
end if
|
|
||||||
end if
|
|
||||||
m.fadeAnimation.control = "stop"
|
|
||||||
m.fadeOpacityInterpolator.reverse = true
|
|
||||||
m.fadeAnimation.control = "start"
|
|
||||||
|
|
||||||
if m.top.isInFocusChain()
|
|
||||||
NodeSetFocus(m.top, true)
|
|
||||||
end if
|
|
||||||
end function
|
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
|
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
|
||||||
<field id="close" type="boolean" alwaysNotify="true" onChange="OnClose" />
|
<field id="close" type="boolean" alwaysNotify="true" onChange="OnClose" />
|
||||||
<field id="minimizeState" type="integer" />
|
<field id="minimizeState" type="integer" />
|
||||||
|
<field id="playerUiState" type="integer" />
|
||||||
<function name="PlayWithContent" />
|
<function name="PlayWithContent" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
@@ -25,7 +26,7 @@
|
|||||||
horizOrigin="right"
|
horizOrigin="right"
|
||||||
translation="[1280,0]" />
|
translation="[1280,0]" />
|
||||||
|
|
||||||
<Group id="VideoUI">
|
<Group id="VideoUi">
|
||||||
<Poster
|
<Poster
|
||||||
id="BackgroundPosterSmall"
|
id="BackgroundPosterSmall"
|
||||||
width="1280"
|
width="1280"
|
||||||
@@ -36,7 +37,7 @@
|
|||||||
width="1280"
|
width="1280"
|
||||||
height="720"
|
height="720"
|
||||||
blendColor="0x323232" />
|
blendColor="0x323232" />
|
||||||
<Group id="TopUI">
|
<Group id="TopUi">
|
||||||
<Poster
|
<Poster
|
||||||
uri="pkg:/images/black-gradient.png"
|
uri="pkg:/images/black-gradient.png"
|
||||||
opacity="0.8"
|
opacity="0.8"
|
||||||
@@ -96,7 +97,7 @@
|
|||||||
</LayoutGroup>
|
</LayoutGroup>
|
||||||
</Group>
|
</Group>
|
||||||
<Group
|
<Group
|
||||||
id="LoadingUI"
|
id="LoadingUi"
|
||||||
visible="false">
|
visible="false">
|
||||||
<Poster
|
<Poster
|
||||||
id="LoadingSpinnerBackground"
|
id="LoadingSpinnerBackground"
|
||||||
@@ -132,11 +133,11 @@
|
|||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Timer id="HideVideoUiTimer" duration="3" />
|
<Timer id="HideVideoUiTimer" duration="3" />
|
||||||
<Animation id="FadeAnimation" duration="0.3" optional="true">
|
<Animation id="UiFadeAnimation" duration="0.3" optional="true">
|
||||||
<FloatFieldInterpolator id="FadeOpacityInterpolator" key="[0.0, 0.5, 1.0]" keyValue="[0.0, 0.5, 1.0]" fieldToInterp="VideoUI.opacity" />
|
<FloatFieldInterpolator id="UiFadeOpacityInterpolator" key="[0.0, 0.5, 1.0]" keyValue="[0.0, 0.5, 1.0]" fieldToInterp="VideoUi.opacity" />
|
||||||
</Animation>
|
</Animation>
|
||||||
|
|
||||||
<Animation id="minimizeAnimation" duration="0.3" optional="true">
|
<Animation id="minimizeAnimation" duration="0.2" optional="true">
|
||||||
<FloatFieldInterpolator id="widthInterpolator" key="[0.0, 0.5, 1.0]" fieldToInterp="VideoPlayer.width" />
|
<FloatFieldInterpolator id="widthInterpolator" key="[0.0, 0.5, 1.0]" fieldToInterp="VideoPlayer.width" />
|
||||||
<FloatFieldInterpolator id="heightInterpolator" key="[0.0, 0.5, 1.0]" fieldToInterp="VideoPlayer.height" />
|
<FloatFieldInterpolator id="heightInterpolator" key="[0.0, 0.5, 1.0]" fieldToInterp="VideoPlayer.height" />
|
||||||
<Vector2DFieldInterpolator id="translationInterpolator" key="[0.0, 0.5, 1.0]" fieldToInterp="VideoPlayer.translation" />
|
<Vector2DFieldInterpolator id="translationInterpolator" key="[0.0, 0.5, 1.0]" fieldToInterp="VideoPlayer.translation" />
|
||||||
|
|||||||
Reference in new issue
Block a user