Pip state machine for dev player
This commit is contained in:
1 parent
37b3e88b93
commit
b9b97c67fd
3 files changed
+173
-80
No files matched your search
@@ -0,0 +1,169 @@
|
||||
enum MinimizeState
|
||||
None ' None is not a valid state, but it is the default value pre-initialization
|
||||
Minimizing
|
||||
Minimized
|
||||
Maximizing
|
||||
Maximized
|
||||
end enum
|
||||
|
||||
function InitializePitctureInPicture()
|
||||
m.minRect = {
|
||||
translation: [834, 460]
|
||||
width: 426
|
||||
height: 240
|
||||
}
|
||||
|
||||
m.maxRect = {
|
||||
translation: [0, 0]
|
||||
width: 1280
|
||||
height: 720
|
||||
}
|
||||
|
||||
InitializePitctureInPictureAnimation()
|
||||
InitializePitctureInPictureFullScreenHint()
|
||||
|
||||
DisposableObserveField(m.top, "minimizeState", FuncName(OnMinimizeStateChange))
|
||||
DisposableObserveFieldScoped(m.container, "fullscreen", FuncName(OnFullScreenChange))
|
||||
|
||||
if m.container.fullscreen
|
||||
m.top.minimizeState = MinimizeState.Maximized
|
||||
else
|
||||
m.top.minimizeState = MinimizeState.Minimized
|
||||
end if
|
||||
end function
|
||||
|
||||
function InitializePitctureInPictureAnimation()
|
||||
m.minimizeAnimation = m.top.findNode("minimizeAnimation")
|
||||
m.widthInterpolator = m.minimizeAnimation.findNode("widthInterpolator")
|
||||
m.heightInterpolator = m.minimizeAnimation.findNode("heightInterpolator")
|
||||
m.translationInterpolator = m.minimizeAnimation.findNode("translationInterpolator")
|
||||
DisposableObserveFieldScoped(m.minimizeAnimation, "state", FuncName(OnMinimizeAnimationStateChange))
|
||||
|
||||
m.widthInterpolator.keyValue = [m.maxRect.width, (m.maxRect.width + m.minRect.width) / 2, m.minRect.width]
|
||||
m.heightInterpolator.keyValue = [m.maxRect.height, (m.maxRect.height + m.minRect.height) / 2, m.minRect.height]
|
||||
midTranslation = [(m.maxRect.translation[0] + m.minRect.translation[0]) / 2, (m.maxRect.translation[1] + m.minRect.translation[1]) / 2]
|
||||
m.translationInterpolator.keyValue = [m.maxRect.translation, midTranslation, m.minRect.translation]
|
||||
end function
|
||||
|
||||
function InitializePitctureInPictureFullScreenHint()
|
||||
m.fullScreenHint = m.top.findNode("fullScreenHint")
|
||||
m.fullScreenHintLabel = m.fullScreenHint.findNode("fullScreenHintLabel")
|
||||
m.fullScreenHintTimer = m.fullScreenHint.findNode("fullScreenHintTimer")
|
||||
DisposableObserveFieldScoped(m.fullScreenHintTimer, "fire", FuncName(HideFullScreenHint))
|
||||
|
||||
m.fullScreenHint.width = m.minRect.width
|
||||
m.fullScreenHintLabel.width = m.minRect.width
|
||||
m.fullScreenHint.translation = [0, m.minRect.height - m.fullScreenHint.height]
|
||||
end function
|
||||
|
||||
function OnMinimizeStateChange()
|
||||
state = m.top.minimizeState
|
||||
|
||||
if state = MinimizeState.Minimizing
|
||||
OnMinimizingState()
|
||||
else if state = MinimizeState.Minimized
|
||||
OnMinimizedState()
|
||||
else if state = MinimizeState.Maximizing
|
||||
OnMaximizingState()
|
||||
else if state = MinimizeState.Maximized
|
||||
OnMaximizedState()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnMinimizingState()
|
||||
m.videoUi.visible = false
|
||||
|
||||
m.widthInterpolator.reverse = false
|
||||
m.heightInterpolator.reverse = false
|
||||
m.translationInterpolator.reverse = false
|
||||
m.minimizeAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnMinimizedState()
|
||||
m.container.fullscreen = false
|
||||
|
||||
m.top.width = m.minRect.width
|
||||
m.top.height = m.minRect.height
|
||||
m.top.translation = m.minRect.translation
|
||||
|
||||
m.videoUi.visible = false
|
||||
ShowFullScreenHint()
|
||||
end function
|
||||
|
||||
function OnMaximizingState()
|
||||
m.videoUi.visible = true
|
||||
HideFullScreenHint()
|
||||
|
||||
m.widthInterpolator.reverse = true
|
||||
m.heightInterpolator.reverse = true
|
||||
m.translationInterpolator.reverse = true
|
||||
m.minimizeAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnMaximizedState()
|
||||
m.container.fullscreen = true
|
||||
|
||||
m.top.width = m.maxRect.width
|
||||
m.top.height = m.maxRect.height
|
||||
m.top.translation = m.maxRect.translation
|
||||
|
||||
HideFullScreenHint()
|
||||
m.videoUi.visible = true
|
||||
end function
|
||||
|
||||
function OnFullScreenChange()
|
||||
if m.container.fullscreen
|
||||
Maximize()
|
||||
else
|
||||
Minimize()
|
||||
end if
|
||||
end function
|
||||
|
||||
function Minimize() as void
|
||||
state = m.top.minimizeState
|
||||
if state = MinimizeState.Minimized
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.minimizeState = MinimizeState.Minimizing
|
||||
end function
|
||||
|
||||
function Maximize() as void
|
||||
state = m.top.minimizeState
|
||||
if state = MinimizeState.Maximized
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.minimizeState = MinimizeState.Maximizing
|
||||
end function
|
||||
|
||||
function ShowFullScreenHint()
|
||||
m.fullScreenHint.visible = true
|
||||
|
||||
m.fullScreenHintTimer.control = "stop"
|
||||
m.fullScreenHintTimer.control = "start"
|
||||
end function
|
||||
|
||||
function HideFullScreenHint()
|
||||
m.fullScreenHint.visible = false
|
||||
end function
|
||||
|
||||
function OnMinimizeAnimationStateChange() 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.minimizeAnimation.control = "stop"
|
||||
if m.minimizeAnimation.state <> "stopped"
|
||||
return
|
||||
end if
|
||||
|
||||
state = m.top.minimizeState
|
||||
if state = MinimizeState.Minimizing
|
||||
m.top.minimizeState = MinimizeState.Minimized
|
||||
else if state = MinimizeState.Maximizing
|
||||
m.top.minimizeState = MinimizeState.Maximized
|
||||
end if
|
||||
end function
|
||||
|
||||
function ShutDownPitctureInPicture()
|
||||
m.fullScreenHintTimer.control = "stop"
|
||||
end function
|
||||
@@ -1,4 +1,5 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/VideoPlayerDev/PictureInPicture.bs"
|
||||
import "pkg:/components/VideoQueue/VideoQueueUtils.bs"
|
||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||
@@ -37,7 +38,7 @@ function Init()
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
SetupMinimizeAnimation()
|
||||
InitializePitctureInPicture()
|
||||
|
||||
DisposableObserveFieldScoped(m.videoQueue, "hasPrevious", FuncName(OnHasPreviousChange))
|
||||
DisposableObserveFieldScoped(m.videoQueue, "hasNext", FuncName(OnHasNextChange))
|
||||
@@ -269,9 +270,9 @@ function OnHideVideoUiTimer()
|
||||
end function
|
||||
|
||||
function OnDispose()
|
||||
ShutDownPitctureInPicture()
|
||||
m.fadeAnimation.control = "stop"
|
||||
m.hideVideoUiTimer.control = "stop"
|
||||
m.fullScreenHintTimer.control = "stop"
|
||||
m.loadingSpinner.control = "stop"
|
||||
m.clock.dispose = true
|
||||
DisposeObservers()
|
||||
@@ -301,83 +302,6 @@ function SetupLoadingSpinner()
|
||||
m.loadingPercentLabel = m.loadingSpinner.findNode("LoadingPercentLabel")
|
||||
end function
|
||||
|
||||
function SetupMinimizeAnimation()
|
||||
m.fullScreenHint = m.top.findNode("fullScreenHint")
|
||||
m.fullScreenHintLabel = m.top.findNode("fullScreenHintLabel")
|
||||
m.fullScreenHintTimer = m.top.findNode("fullScreenHintTimer")
|
||||
DisposableObserveFieldScoped(m.fullScreenHintTimer, "fire", FuncName(OnFullScreenHintTimer))
|
||||
|
||||
m.minimizeAnimation = m.top.findNode("minimizeAnimation")
|
||||
m.widthInterpolator = m.top.findNode("widthInterpolator")
|
||||
m.heightInterpolator = m.top.findNode("heightInterpolator")
|
||||
m.translationInterpolator = m.top.findNode("translationInterpolator")
|
||||
|
||||
minRect = m.top.minRect
|
||||
maxRect = m.top.maxRect
|
||||
|
||||
m.widthInterpolator.keyValue = [maxRect.width, (maxRect.width + minRect.width) / 2, minRect.width]
|
||||
m.heightInterpolator.keyValue = [maxRect.height, (maxRect.height + minRect.height) / 2, minRect.height]
|
||||
maxTranslation = [maxRect.x, maxRect.y]
|
||||
minTranslation = [minRect.x, minRect.y]
|
||||
midTranslation = [(maxRect.x + minRect.x) / 2, (maxRect.y + minRect.y) / 2]
|
||||
m.translationInterpolator.keyValue = [maxTranslation, midTranslation, minTranslation]
|
||||
|
||||
fullscreen = m.container.fullscreen
|
||||
rect = fullscreen ? 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]
|
||||
|
||||
m.top.showFullScreenHint = not fullscreen
|
||||
m.videoUi.visible = fullscreen
|
||||
|
||||
DisposableObserveFieldScoped(m.container, "fullscreen", FuncName(OnFullScreenChange))
|
||||
end function
|
||||
|
||||
function OnFullScreenChange()
|
||||
fullscreen = m.container.fullscreen
|
||||
|
||||
m.widthInterpolator.reverse = fullscreen
|
||||
m.heightInterpolator.reverse = fullscreen
|
||||
m.translationInterpolator.reverse = fullscreen
|
||||
m.minimizeAnimation.control = "start"
|
||||
|
||||
m.videoUi.visible = fullscreen
|
||||
m.top.showFullScreenHint = not fullscreen
|
||||
end function
|
||||
|
||||
function OnFullScreenHintTimer()
|
||||
showFullScreenHint = m.top.showFullScreenHint
|
||||
m.fullScreenHint.visible = showFullScreenHint
|
||||
if showFullScreenHint
|
||||
m.top.showFullScreenHint = false
|
||||
end if
|
||||
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 ShowVideoUi() as boolean
|
||||
if m.fadeAnimation.state = "stopped"
|
||||
if m.videoUi.opacity = 1
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
<field id="previousPlayer" type="node" />
|
||||
<field id="minRect" type="rect2D" value="[834,460,426,240]" />
|
||||
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
|
||||
<field id="showFullScreenHint" type="boolean" alwaysNotify="true" onChange="OnShowFullScreenHint" />
|
||||
<field id="close" type="boolean" alwaysNotify="true" onChange="OnClose" />
|
||||
<field id="minimizeState" type="integer" />
|
||||
<function name="PlayWithContent" />
|
||||
</interface>
|
||||
<children>
|
||||
|
||||
Reference in new issue
Block a user