Files
playlet-piped/playlet-lib/src/components/VideoPlayer/Video.bs
T
Brahim Hadricheandgithub-action linter 9d8a3d1cea Create Component Library (#43)
* Move src under playlet-lib

* Update configuration

* Update script

* Update script

* Working version

* Vs code config WIP

* Package lock sync

* Lint fix

* Fix images

* Reuse config files

* Kind of a working setup

* Lock node version

* Rename scripts to tools

* Fix build scripts, lib url system

* Lint fix

* rale

* Fix args and web server

* Load fallbacks and build script cleanups

* Remove unused method

* no message

* no message

* Remove generic message field

* Lint fix

* no message

* Use loading indicator on main app

* Add playlet lib version to settings

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
2023-01-29 16:50:28 -05:00

81 lines
2.6 KiB
Plaintext

import "pkg:/source/services/Invidious.bs"
import "pkg:/components/Dialog/DialogUtils.bs"
function PlayVideo(videoId as string, args = invalid as object)
sender = args?.sender
metadata = args?.metadata
if metadata <> invalid and GetInterface(metadata, "ifSGNodeField") <> invalid
metadata = args.metadata.getFields()
end if
width = 1280
height = 720
translation = [0.0, 0.0]
videoContainer = GetVideoContainer()
if videoContainer.videoPlayer <> invalid
width = videoContainer.videoPlayer.width
height = videoContainer.videoPlayer.height
translation = videoContainer.videoPlayer.translation
end if
CloseVideo(false)
if sender <> invalid
videoContainer.sender = sender
end if
videoContainer.videoPlayer = videoContainer.createChild("VideoPlayer")
videoContainer.videoPlayer.id = "VideoPlayer"
videoContainer.videoPlayer.metadata = metadata
videoContainer.videoPlayer.videoId = videoId
videoContainer.videoPlayer.width = width
videoContainer.videoPlayer.height = height
videoContainer.videoPlayer.translation = translation
if videoContainer.fullscreen
videoContainer.videoPlayer.SetFocus(true)
end if
end function
function CloseVideo(setFocus = true as boolean)
videoContainer = GetVideoContainer()
if videoContainer.videoPlayer <> invalid
videoContainer.videoPlayer.control = "stop"
videoContainer.RemoveChild(videoContainer.videoPlayer)
videoContainer.videoPlayer = invalid
end if
if setFocus and videoContainer.sender <> invalid
if videoContainer.sender.hasField("focus")
videoContainer.sender.focus = true
else
videoContainer.sender.SetFocus(true)
end if
end if
end function
function ToggleVideoPictureInPicture(sender = invalid as object) as boolean
videoContainer = GetVideoContainer()
if videoContainer.videoPlayer = invalid
return false
end if
videoContainer.fullscreen = not videoContainer.fullscreen
if sender <> invalid
videoContainer.sender = sender
end if
if videoContainer.fullscreen
videoContainer.videoPlayer.SetFocus(true)
else
if videoContainer.sender <> invalid
if videoContainer.sender.hasField("focus")
videoContainer.sender.focus = true
else
videoContainer.sender.SetFocus(true)
end if
end if
videoContainer.sender = invalid
end if
return true
end function
function GetVideoContainer() as object
return m.global.videoContainer
end function