From 37b3e88b931e286431309f4b1012d0f490684798 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 4 Jul 2024 13:59:57 -0400 Subject: [PATCH] Background poster in dev player --- .../VideoPlayerDev/VideoContentTaskDev.bs | 10 +++- .../VideoPlayerDev/VideoPlayerDev.bs | 46 ++++++++++++++----- .../VideoPlayerDev/VideoPlayerDev.xml | 25 ++++++++-- 3 files changed, 64 insertions(+), 17 deletions(-) diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs index 93da6777..92b21ee7 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs +++ b/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs @@ -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 diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs index ff0b987f..cf8cac5c 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs @@ -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 diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml index a3d0d098..cc131c4c 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml @@ -26,7 +26,16 @@ translation="[1280,0]" /> - + + - + + + spinInterval="1">