124 lines
3.6 KiB
Plaintext
124 lines
3.6 KiB
Plaintext
import "pkg:/components/Dialog/DialogUtils.bs"
|
|
import "pkg:/source/utils/FocusManagement.bs"
|
|
import "pkg:/source/utils/StringUtils.bs"
|
|
|
|
namespace VideoUtils
|
|
function PlayVideo(contentNode as object) as void
|
|
CloseVideo(false)
|
|
|
|
container = GetVideoContainer()
|
|
' There should be no reason for this to be invalid, but there was a crash report
|
|
' with this being invalid, so we'll abort playing a video and try to restore focus to the top screen
|
|
if container = invalid
|
|
LogError("VideoContainer not found! Attempting to restore focus to top screen...")
|
|
appController = m.top.getScene().findNode("AppController")
|
|
if appController <> invalid
|
|
appController@.FocusTopScreen()
|
|
end if
|
|
DialogUtils.ShowDialog(`VideoContainer not found!\nPlease try again. If the problem persist, contact Playlet authors.`, "Error playing video")
|
|
return
|
|
end if
|
|
videoPlayer = container.createChild("videoPlayer")
|
|
videoPlayer.id = "VideoPlayer"
|
|
videoPlayer@.BindNode()
|
|
|
|
videoPlayer@.PlayWithContent(contentNode)
|
|
|
|
if container.fullscreen
|
|
NodeSetFocus(videoPlayer, true)
|
|
|
|
dialog = m.top.getScene().dialog
|
|
if dialog <> invalid
|
|
dialog.close = true
|
|
end if
|
|
end if
|
|
end function
|
|
|
|
function CloseVideo(setFocus = true as boolean) as void
|
|
videoPlayer = GetVideoPlayer()
|
|
if videoPlayer = invalid
|
|
return
|
|
end if
|
|
videoPlayer@.Close()
|
|
|
|
if setFocus
|
|
videoPlayer.appController@.FocusTopScreen()
|
|
end if
|
|
end function
|
|
|
|
function GetVideoPlayer() as object
|
|
container = GetVideoContainer()
|
|
if container = invalid or container.getChildCount() = 0
|
|
return invalid
|
|
end if
|
|
return container.getChild(0)
|
|
end function
|
|
|
|
function GetVideoContainer() as object
|
|
return m.top.getScene().findNode("VideoContainer")
|
|
end function
|
|
|
|
function IsVideoPlayerFullScreen() as boolean
|
|
videoContainer = GetVideoContainer()
|
|
if videoContainer = invalid
|
|
return false
|
|
end if
|
|
return videoContainer.fullscreen
|
|
end function
|
|
|
|
function ToggleVideoPictureInPicture() as boolean
|
|
videoPlayer = GetVideoPlayer()
|
|
if videoPlayer = invalid
|
|
return false
|
|
end if
|
|
videoContainer = GetVideoContainer()
|
|
videoContainer.fullscreen = not videoContainer.fullscreen
|
|
if videoContainer.fullscreen
|
|
NodeSetFocus(videoPlayer, true)
|
|
else
|
|
videoPlayer.appController@.FocusTopScreen()
|
|
end if
|
|
return true
|
|
end function
|
|
|
|
function IsVideoPlayerOpen() as boolean
|
|
return GetVideoPlayer() <> invalid
|
|
end function
|
|
|
|
function PauseVideo() as boolean
|
|
player = GetVideoPlayer()
|
|
if player = invalid
|
|
return false
|
|
end if
|
|
player.control = "pause"
|
|
return true
|
|
end function
|
|
|
|
function ResumeVideo() as boolean
|
|
player = GetVideoPlayer()
|
|
if player = invalid
|
|
return false
|
|
end if
|
|
player.control = "resume"
|
|
return true
|
|
end function
|
|
|
|
function TogglePause() as boolean
|
|
player = GetVideoPlayer()
|
|
if player = invalid
|
|
return false
|
|
end if
|
|
if player.state = "playing"
|
|
player.control = "pause"
|
|
return true
|
|
else if player.state = "paused"
|
|
player.control = "resume"
|
|
return true
|
|
end if
|
|
return false
|
|
end function
|
|
|
|
end namespace
|
|
|
|
|