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 00000000..de44236b Binary files /dev/null and b/playlet-lib/src/images/icons/player/next.png differ diff --git a/playlet-lib/src/images/icons/player/next.svg b/playlet-lib/src/images/icons/player/next.svg new file mode 100644 index 00000000..6283d584 --- /dev/null +++ b/playlet-lib/src/images/icons/player/next.svg @@ -0,0 +1,3 @@ + + + \ 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 00000000..594348af Binary files /dev/null and b/playlet-lib/src/images/icons/player/pause.png differ diff --git a/playlet-lib/src/images/icons/player/pause.svg b/playlet-lib/src/images/icons/player/pause.svg new file mode 100644 index 00000000..0d77d19a --- /dev/null +++ b/playlet-lib/src/images/icons/player/pause.svg @@ -0,0 +1,3 @@ + + + \ 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 00000000..805b210e Binary files /dev/null and b/playlet-lib/src/images/icons/player/play.png differ diff --git a/playlet-lib/src/images/icons/player/play.svg b/playlet-lib/src/images/icons/player/play.svg new file mode 100644 index 00000000..32f5c5e0 --- /dev/null +++ b/playlet-lib/src/images/icons/player/play.svg @@ -0,0 +1,3 @@ + + + \ 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 00000000..92b625ea Binary files /dev/null and b/playlet-lib/src/images/icons/player/previous.png differ 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