Background poster in dev player

This commit is contained in:
Brahim Hadriche committed 2024-07-04 13:59:57 -04:00
1 parent 38e8856b09
commit 37b3e88b93
3 files changed
+64 -17

No files matched your search

@@ -5,19 +5,25 @@ import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
function VideoContentTaskDev(input as object) as object
titleLabel = input.titleLabel
secondaryTitleLabel = input.secondaryTitleLabel
backgroundPoster = input.backgroundPoster
contentNode = input.content
invidiousNode = input.invidious
titleLabel.text = contentNode.title
secondaryTitleLabel.text = contentNode.secondaryTitle
if StringUtils.IsNullOrEmpty(contentNode.videoId)
videoId = contentNode.videoId
if StringUtils.IsNullOrEmpty(videoId)
throw "Can't load video information: videoId is missing"
end if
service = new Invidious.InvidiousService(invidiousNode)
instance = service.GetInstance()
response = service.GetVideoMetadata(contentNode.videoId, { cancellation: m.top.cancellation })
backgroundPoster.uri = `${instance}/vi/${videoId}/maxresdefault.jpg`
response = service.GetVideoMetadata(videoId, { cancellation: m.top.cancellation })
if m.top.cancel
return invalid
@@ -20,6 +20,8 @@ function Init()
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")
@@ -71,15 +73,25 @@ end function
function PlayWithContent(contentNode as object)
videoContentNode = CreateObject("roSGNode", "ContentNode")
if not StringUtils.IsNullOrEmpty(contentNode.videoId)
videoContentNode.AddFields({ videoId: contentNode.videoId })
videoId = contentNode.videoId
title = contentNode.title
author = contentNode._author
thumbnail = contentNode.thumbnail
if not StringUtils.IsNullOrEmpty(videoId)
videoContentNode.AddFields({ videoId: videoId })
end if
if not StringUtils.IsNullOrEmpty(contentNode.title)
videoContentNode.title = contentNode.title
if not StringUtils.IsNullOrEmpty(title)
videoContentNode.title = title
end if
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
if not StringUtils.IsNullOrEmpty(contentNode._author)
videoContentNode.secondaryTitle = contentNode._author
if not StringUtils.IsNullOrEmpty(author)
videoContentNode.secondaryTitle = author
end if
if not StringUtils.IsNullOrEmpty(thumbnail)
videoContentNode.thumbnail = thumbnail
m.backgroundPosterSmall.uri = thumbnail
end if
StartVideoContentTask(videoContentNode)
@@ -94,7 +106,7 @@ function StartVideoContentTask(videoContentNode as object)
m.loadingLabel.text = Tr(Locale.VideoPlayer.Loading)
m.loadingPercentLabel.text = ""
m.loadingSpinner.visible = true
m.loadingUi.visible = true
m.loadingSpinner.control = "start"
m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTaskDev, {
@@ -102,6 +114,7 @@ function StartVideoContentTask(videoContentNode as object)
secondaryTitleLabel: m.secondaryTitleLabel
content: videoContentNode
invidious: m.top.invidious
backgroundPoster: m.backgroundPoster
}, OnVideoContentTaskResults)
end function
@@ -202,7 +215,7 @@ function OnPlayerStateChange() as void
state = m.top.state
if state = "stopping" or state = "stopped"
m.videoUi.Visible = false
m.videoUi.visible = false
return
end if
@@ -221,10 +234,14 @@ function OnPlayerStateChange() as void
if state = "buffering"
m.loadingLabel.text = Tr(Locale.VideoPlayer.Buffering)
m.loadingSpinner.control = "start"
m.loadingSpinner.visible = true
m.loadingUi.visible = true
m.backgroundPoster.visible = true
m.backgroundPosterSmall.visible = true
else
m.loadingSpinner.control = "stop"
m.loadingSpinner.visible = false
m.loadingUi.visible = false
m.backgroundPoster.visible = false
m.backgroundPosterSmall.visible = false
end if
end function
@@ -261,7 +278,9 @@ function OnDispose()
end function
function SetupLoadingSpinner()
m.loadingSpinner = m.top.findNode("LoadingSpinner")
m.loadingUi = m.top.findNode("LoadingUI")
m.loadingSpinnerBackground = m.loadingUi.findNode("LoadingSpinnerBackground")
m.loadingSpinner = m.loadingUi.findNode("LoadingSpinner")
poster = m.loadingSpinner.poster
size = 150
@@ -273,6 +292,11 @@ function SetupLoadingSpinner()
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
@@ -26,7 +26,16 @@
translation="[1280,0]" />
<Group id="VideoUI">
<Poster
id="BackgroundPosterSmall"
width="1280"
height="720"
blendColor="0x323232" />
<Poster
id="BackgroundPoster"
width="1280"
height="720"
blendColor="0x323232" />
<Group id="TopUI">
<Poster
uri="pkg:/images/black-gradient.png"
@@ -86,11 +95,19 @@
iconUri="pkg:/images/icons/player/minimize.png" />
</LayoutGroup>
</Group>
<Group>
<Group
id="LoadingUI"
visible="false">
<Poster
id="LoadingSpinnerBackground"
width="80"
height="80"
uri="pkg:/images/white-circle.png"
opacity="0.4"
blendColor="0x000000" />
<BusySpinner
id="LoadingSpinner"
spinInterval="1"
visible="false">
spinInterval="1">
<Label
id="LoadingPercentLabel"
horizAlign="center"