From 5c215ca974f5481454f5c3c54524ef8c0d9ad852 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 28 Jun 2024 12:29:23 -0400 Subject: [PATCH] Add some UI to dev player --- playlet-lib/src/components/Clock/Clock.bs | 5 + playlet-lib/src/components/Clock/Clock.xml | 2 +- .../VideoPlayerDev/VideoContentTaskDev.bs | 20 +++- .../VideoPlayerDev/VideoPlayerButton.bs | 54 +++++++++++ .../VideoPlayerDev/VideoPlayerButton.xml | 29 ++++++ .../VideoPlayerDev/VideoPlayerDev.bs | 87 +++++++++++++++++- .../VideoPlayerDev/VideoPlayerDev.xml | 43 ++++++++- playlet-lib/src/images/icons/player/next.png | Bin 0 -> 247 bytes playlet-lib/src/images/icons/player/next.svg | 3 + .../images/icons/player/next.svg.meta.json5 | 11 +++ playlet-lib/src/images/icons/player/pause.png | Bin 0 -> 189 bytes playlet-lib/src/images/icons/player/pause.svg | 3 + .../images/icons/player/pause.svg.meta.json5 | 11 +++ playlet-lib/src/images/icons/player/play.png | Bin 0 -> 251 bytes playlet-lib/src/images/icons/player/play.svg | 3 + .../images/icons/player/play.svg.meta.json5 | 11 +++ .../src/images/icons/player/previous.png | Bin 0 -> 261 bytes .../src/images/icons/player/previous.svg | 3 + .../icons/player/previous.svg.meta.json5 | 11 +++ 19 files changed, 292 insertions(+), 4 deletions(-) create mode 100644 playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.bs create mode 100644 playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.xml create mode 100644 playlet-lib/src/images/icons/player/next.png create mode 100644 playlet-lib/src/images/icons/player/next.svg create mode 100644 playlet-lib/src/images/icons/player/next.svg.meta.json5 create mode 100644 playlet-lib/src/images/icons/player/pause.png create mode 100644 playlet-lib/src/images/icons/player/pause.svg create mode 100644 playlet-lib/src/images/icons/player/pause.svg.meta.json5 create mode 100644 playlet-lib/src/images/icons/player/play.png create mode 100644 playlet-lib/src/images/icons/player/play.svg create mode 100644 playlet-lib/src/images/icons/player/play.svg.meta.json5 create mode 100644 playlet-lib/src/images/icons/player/previous.png create mode 100644 playlet-lib/src/images/icons/player/previous.svg create mode 100644 playlet-lib/src/images/icons/player/previous.svg.meta.json5 diff --git a/playlet-lib/src/components/Clock/Clock.bs b/playlet-lib/src/components/Clock/Clock.bs index cf923c70..885544a6 100644 --- a/playlet-lib/src/components/Clock/Clock.bs +++ b/playlet-lib/src/components/Clock/Clock.bs @@ -60,3 +60,8 @@ function Update() m.top.text = hoursStr + ":" + minutesStr + " " + ampm end function + +function OnDispose() + m.timer.control = "stop" + m.timer.unobserveField("fire") +end function diff --git a/playlet-lib/src/components/Clock/Clock.xml b/playlet-lib/src/components/Clock/Clock.xml index ac81c668..c9664ded 100644 --- a/playlet-lib/src/components/Clock/Clock.xml +++ b/playlet-lib/src/components/Clock/Clock.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs index 4cb3c588..9a28593e 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs +++ b/playlet-lib/src/components/VideoPlayerDev/VideoContentTaskDev.bs @@ -1,10 +1,15 @@ import "pkg:/components/Services/Invidious/InvidiousService.bs" +import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs" @asynctask function VideoContentTaskDev(input as object) as object + titleLabel = input.titleLabel + secondaryTitleLabel = input.secondaryTitleLabel contentNode = input.content invidiousNode = input.invidious + titleLabel.text = contentNode.title + if StringUtils.IsNullOrEmpty(contentNode.videoId) throw "Can't load video information: videoId is missing" end if @@ -27,7 +32,20 @@ function VideoContentTaskDev(input as object) as object end if contentNode.title = metadata.title - contentNode.secondaryTitle = metadata.author + titleLabel.text = metadata.title + + secondaryTitle = `${metadata.author}` + viewCount = InvidiousContent.VideoGetViewCountText(metadata) + if not StringUtils.IsNullOrEmpty(viewCount) + secondaryTitle = `${secondaryTitle} • ${viewCount}` + end if + pubslishedText = InvidiousContent.VideoGetPublishedText(metadata) + if not StringUtils.IsNullOrEmpty(pubslishedText) + secondaryTitle = `${secondaryTitle} • ${pubslishedText}` + end if + + contentNode.secondaryTitle = secondaryTitle + secondaryTitleLabel.text = secondaryTitle contentNode.live = metadata.liveNow streamUrls = [`http://127.0.0.1:8888/api/dash?v=${metadata.videoId}`] diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.bs b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.bs new file mode 100644 index 00000000..317152ea --- /dev/null +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.bs @@ -0,0 +1,54 @@ +import "pkg:/source/utils/Types.bs" + +function Init() + m.background = m.top.findNode("background") + m.icon = m.top.findNode("icon") + + OnDisabledChange() + + m.top.observeField("focusedChild", FuncName(OnFocusedChild)) +end function + +function OnFocusedChild() + m.top.buttonFocused = m.top.hasFocus() +end function + +function OnButtonFocused() + buttonFocused = m.top.buttonFocused + + if buttonFocused + m.background.blendColor = m.top.focusedBackgroundColor + m.icon.blendColor = m.top.focusedIconColor + else + m.background.blendColor = m.top.backgroundColor + m.icon.blendColor = m.top.iconColor + end if +end function + +function OnDisabledChange() + disabled = m.top.disabled + + if disabled + m.background.blendColor = m.top.disabledBackgroundColor + m.icon.blendColor = m.top.disabledIconColor + else + OnButtonFocused() + end if + m.top.focusable = not disabled +end function + +function OnkeyEvent(key as string, press as boolean) as boolean + if not press + return false + end if + + if key = "OK" + disabled = m.top.disabled + if not disabled + m.top.buttonSelected = true + end if + return true + end if + + return false +end function diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.xml b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.xml new file mode 100644 index 00000000..3b4ad788 --- /dev/null +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerButton.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs index 02e6c2bb..fb185cba 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs @@ -1,7 +1,9 @@ -import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" +import "pkg:/components/Navigation/Navigation.bs" import "pkg:/source/AsyncTask/AsyncTask.bs" import "pkg:/source/AsyncTask/Tasks.bs" +import "pkg:/source/utils/DisposableObserve.bs" import "pkg:/source/utils/ErrorUtils.bs" +import "pkg:/source/utils/FocusManagement.bs" import "pkg:/source/utils/Logging.bs" import "pkg:/source/utils/StringUtils.bs" import "pkg:/source/utils/Types.bs" @@ -12,6 +14,42 @@ function Init() httpAgent = m.top.getHttpAgent() httpAgent.AddHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0") + + m.clock = m.top.findNode("Clock") + + m.titleLabel = m.top.findNode("TitleLabel") + m.secondaryTitleLabel = m.top.findNode("SecondaryTitleLabel") + + m.previousButton = m.top.findNode("PreviousButton") + m.playButton = m.top.findNode("PlayButton") + m.nextButton = m.top.findNode("NextButton") + + DisposableObserveFieldScoped(m.playButton, "buttonSelected", FuncName(OnPlayButtonSelected)) + + DisposableObserveField(m.top, "state", FuncName(OnPlayerStateChange)) + + SetNavigation(m.previousButton, "right", m.playButton) + SetNavigation(m.playButton, "left", m.previousButton) + SetNavigation(m.playButton, "right", m.nextButton) + SetNavigation(m.nextButton, "left", m.playButton) +end function + +function OnNodeReady() + DisposableObserveFieldScoped(m.videoQueue, "hasPrevious", FuncName(OnHasPreviousChange)) + DisposableObserveFieldScoped(m.videoQueue, "hasNext", FuncName(OnHasNextChange)) + OnHasPreviousChange() + OnHasNextChange() + + DisposableObserveFieldScoped(m.previousButton, "buttonSelected", FuncName(OnPreviousButtonSelected)) + DisposableObserveFieldScoped(m.nextButton, "buttonSelected", FuncName(OnNextButtonSelected)) +end function + +function OnFocusChange() as void + if not m.top.focus + return + end if + + NodeSetFocus(m.playButton, true) end function function PlayWithContent(contentNode as object) @@ -39,6 +77,8 @@ function StartVideoContentTask(videoContentNode as object) m.top.content = videoContentNode m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTaskDev, { + titleLabel: m.titleLabel + secondaryTitleLabel: m.secondaryTitleLabel content: videoContentNode invidious: m.top.invidious }, OnVideoContentTaskResults) @@ -81,9 +121,15 @@ function OnClose() m.top.control = "stop" m.top.content = invalid + + m.top.dispose = true end function function OnkeyEvent(key as string, press as boolean) as boolean + if NavigationKeyHandler(key, press).handled + return true + end if + if press = false return false end if @@ -95,3 +141,42 @@ function OnkeyEvent(key as string, press as boolean) as boolean return false end function + +function OnHasPreviousChange() + m.previousButton.disabled = not m.videoQueue.hasPrevious +end function + +function OnHasNextChange() + m.nextButton.disabled = not m.videoQueue.hasNext +end function + +function OnPlayButtonSelected() + state = m.top.state + if state = "playing" + m.top.control = "pause" + else if state = "paused" + m.top.control = "resume" + end if +end function + +function OnPreviousButtonSelected() + m.videoQueue.previous = true +end function + +function OnNextButtonSelected() + m.videoQueue.next = true +end function + +function OnPlayerStateChange() + state = m.top.state + if state = "playing" + m.playButton.iconUri = "pkg:/images/icons/player/pause.png" + else if state = "paused" + m.playButton.iconUri = "pkg:/images/icons/player/play.png" + end if +end function + +function OnDispose() + m.clock.dispose = true + DisposeObservers() +end function diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml index 62e2c9cc..869f6311 100644 --- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml +++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml @@ -5,7 +5,7 @@ This would allow us to be flexible with the UI beyond the customizations of the stock Roku Video component. --> - + @@ -20,5 +20,46 @@ fontUri="font:SmallestBoldSystemFont" horizOrigin="right" translation="[1280,0]" /> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/next.png b/playlet-lib/src/images/icons/player/next.png new file mode 100644 index 0000000000000000000000000000000000000000..de44236be1f2a81f4781f0ae4532c2fb4904f906 GIT binary patch literal 247 zcmeAS@N?(olHy`uVBq!ia0vp^S|H591|*LjJ{b+97>k44ofy`glX(f`Z1i+-42fuc zd+i}_lYvCb!_~qTP09vL${RZK7D#sr8#LuLDDOD + + \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/next.svg.meta.json5 b/playlet-lib/src/images/icons/player/next.svg.meta.json5 new file mode 100644 index 00000000..404aa523 --- /dev/null +++ b/playlet-lib/src/images/icons/player/next.svg.meta.json5 @@ -0,0 +1,11 @@ +{ + inputHash: '47b418d19c4a17a96e1688ce4a66afd3', + outputs: [ + { + outputFilePath: 'images/icons/player/next.png', + outputHash: '3929e6ecf1c1f89ce90002e1c1a3fc5a', + width: 42, + height: 42, + }, + ], +} \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/pause.png b/playlet-lib/src/images/icons/player/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..594348afe844669502b30cfcead4453bf447ae17 GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^S|H591|*LjJ{b+97>k44ofy`glX(f`lzX~3hD5Z! zy?&6lL4n8N;x*S45w~I!_XEBKO;x5HY7U2w{_peU{2wLAz;MB_T7Fifh~VyCzfj+) zdli(j4edfqzyG^?WZt*wd)ID~j{YBgZ1Qu3E7A+^aeQ@KVeYh7@KtX>eoK|Kt?Ro_ l$2Enz3TKsdF))0{7jKKOuTgsbaXZin44$rjF6*2UngA + + \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/pause.svg.meta.json5 b/playlet-lib/src/images/icons/player/pause.svg.meta.json5 new file mode 100644 index 00000000..534187ba --- /dev/null +++ b/playlet-lib/src/images/icons/player/pause.svg.meta.json5 @@ -0,0 +1,11 @@ +{ + inputHash: 'd0a9a71afade6f9241106afc0591e3cc', + outputs: [ + { + outputFilePath: 'images/icons/player/pause.png', + outputHash: '450d213581d144e89fe4b819cc4bdd4d', + width: 42, + height: 42, + }, + ], +} \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/play.png b/playlet-lib/src/images/icons/player/play.png new file mode 100644 index 0000000000000000000000000000000000000000..805b210eedbdc67122e2bb5ac54edb112aa7afc4 GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^S|H591|*LjJ{b+97>k44ofy`glX(f`Z1r?;42fuc zdo7mtkby|sLuRfC4J;}OjOq^O~z>wDn}tLo+d>l%AbK9=-5dfmn~{@1hzvo#s5w;wok;RAc! zX^y&u>`n1rQcdxng*JSAcY + + \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/play.svg.meta.json5 b/playlet-lib/src/images/icons/player/play.svg.meta.json5 new file mode 100644 index 00000000..0867782e --- /dev/null +++ b/playlet-lib/src/images/icons/player/play.svg.meta.json5 @@ -0,0 +1,11 @@ +{ + inputHash: '0f4c0d80bb171a299e11feb8046a2057', + outputs: [ + { + outputFilePath: 'images/icons/player/play.png', + outputHash: '555f536f9a06df6dd3deaed97677bf0b', + width: 42, + height: 42, + }, + ], +} \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/previous.png b/playlet-lib/src/images/icons/player/previous.png new file mode 100644 index 0000000000000000000000000000000000000000..92b625ead7320783219aa0d7a6880becb529829a GIT binary patch literal 261 zcmeAS@N?(olHy`uVBq!ia0vp^S|H591|*LjJ{b+97>k44ofy`glX(f`?DuqW42fuc zd*x#8p#TAwi`i3{G#Z684yp!lsb1hzWe{D`vV>VfQT9$v14AU|rZuKj^2PhYH!DZ~ zR!{4u%5uG#@!NrAM&exiSL|XucP2pSRef#vobvFnEw6VeZ(#BZov9iZyLVS; zeVh3GPoKZst+}{-=QjC22XofP&C;)$9lz@M&T3Z|7Z;WT`m>k+yL0|RX*19(44$rj JF6*2UngFnraUuW! literal 0 HcmV?d00001 diff --git a/playlet-lib/src/images/icons/player/previous.svg b/playlet-lib/src/images/icons/player/previous.svg new file mode 100644 index 00000000..674b78f5 --- /dev/null +++ b/playlet-lib/src/images/icons/player/previous.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/playlet-lib/src/images/icons/player/previous.svg.meta.json5 b/playlet-lib/src/images/icons/player/previous.svg.meta.json5 new file mode 100644 index 00000000..2dfe63ef --- /dev/null +++ b/playlet-lib/src/images/icons/player/previous.svg.meta.json5 @@ -0,0 +1,11 @@ +{ + inputHash: '735b2a65cb33717b6848f1d17e343908', + outputs: [ + { + outputFilePath: 'images/icons/player/previous.png', + outputHash: '4b61ec70865f95fdaf3fd150097e2fd2', + width: 42, + height: 42, + }, + ], +} \ No newline at end of file