Add some UI to dev player

This commit is contained in:
Brahim Hadriche committed 2024-06-28 12:29:23 -04:00
1 parent 43b62a0ef8
commit 5c215ca974
19 files changed
+292 -4

No files matched your search

@@ -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
+1 -1
View File
@@ -1,2 +1,2 @@
<component name="Clock" extends="Label">
<component name="Clock" extends="Label" includes="Disposable">
</component>
@@ -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}`]
@@ -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
@@ -0,0 +1,29 @@
<component name="VideoPlayerButton" extends="Group">
<interface>
<field id="backgroundColor" type="color" value="#3C3C3C" />
<field id="focusedBackgroundColor" type="color" value="#DDDDDD" />
<field id="disabledBackgroundColor" type="color" value="#292929" />
<field id="iconUri" type="uri" alias="icon.uri" />
<field id="iconColor" type="color" value="#DDDDDD" />
<field id="focusedIconColor" type="color" value="#262626" />
<field id="disabledIconColor" type="color" value="#606060" />
<field id="disabled" type="boolean" onChange="OnDisabledChange" />
<field id="buttonFocused" type="boolean" onChange="OnButtonFocused" />
<field id="buttonSelected" type="boolean" alwaysNotify="true" />
</interface>
<children>
<Poster
id="background"
uri="pkg:/images/white-circle.png"
width="42"
height="42">
<Poster
id="icon"
width="42"
height="42">
</Poster>
</Poster>
</children>
</component>
@@ -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
@@ -5,7 +5,7 @@
This would allow us to be flexible with the UI beyond the customizations
of the stock Roku Video component.
-->
<component name="VideoPlayerDev" extends="Video" includes="AutoBind">
<component name="VideoPlayerDev" extends="Video" includes="AutoBind,Focus,Disposable">
<interface>
<field id="videoQueue" type="node" bind="../../VideoQueue" />
<field id="invidious" type="node" bind="../../Invidious" />
@@ -20,5 +20,46 @@
fontUri="font:SmallestBoldSystemFont"
horizOrigin="right"
translation="[1280,0]" />
<Group id="TopUI">
<!--
TODO:P2 once VideoPlayerDev replaces VideoPlayer, the clock can
be removed to reuse the Clock from MainScene
-->
<Clock id="Clock" />
<LayoutGroup
itemSpacings="[5]"
translation="[68,40]">
<Label
id="TitleLabel"
font="font:LargeBoldSystemFont"
width="900"
wrap="true" />
<Label
id="SecondaryTitleLabel"
font="font:SmallestSystemFont"
width="900"
wrap="true" />
</LayoutGroup>
</Group>
<Group>
<LayoutGroup
layoutDirection="horiz"
horizAlignment="center"
itemSpacings="[15]"
translation="[640,600]">
<VideoPlayerButton
id="PreviousButton"
iconUri="pkg:/images/icons/player/previous.png"
disabled="true" />
<VideoPlayerButton
id="PlayButton"
iconUri="pkg:/images/icons/player/play.png" />
<VideoPlayerButton
id="NextButton"
iconUri="pkg:/images/icons/player/next.png"
disabled="true" />
</LayoutGroup>
</Group>
</children>
</component>
Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<path fill="#FFFFFF" d="M 12,24 20.5,18 12,12 V 24 z M 22,12 v 12 h 2 V 12 h -2 z"></path>
</svg>

After

Width:  |  Height:  |  Size: 162 B

@@ -0,0 +1,11 @@
{
inputHash: '47b418d19c4a17a96e1688ce4a66afd3',
outputs: [
{
outputFilePath: 'images/icons/player/next.png',
outputHash: '3929e6ecf1c1f89ce90002e1c1a3fc5a',
width: 42,
height: 42,
},
],
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<path fill="#FFFFFF" d="M 12,26 16,26 16,10 12,10 z M 21,26 25,26 25,10 21,10 z"></path>
</svg>

After

Width:  |  Height:  |  Size: 160 B

@@ -0,0 +1,11 @@
{
inputHash: 'd0a9a71afade6f9241106afc0591e3cc',
outputs: [
{
outputFilePath: 'images/icons/player/pause.png',
outputHash: '450d213581d144e89fe4b819cc4bdd4d',
width: 42,
height: 42,
},
],
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<path fill="#FFFFFF" d="M 12,26 18.5,22 18.5,14 12,10 z M 18.5,22 25,18 25,18 18.5,14 z"></path>
</svg>

After

Width:  |  Height:  |  Size: 168 B

@@ -0,0 +1,11 @@
{
inputHash: '0f4c0d80bb171a299e11feb8046a2057',
outputs: [
{
outputFilePath: 'images/icons/player/play.png',
outputHash: '555f536f9a06df6dd3deaed97677bf0b',
width: 42,
height: 42,
},
],
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<path fill="#FFFFFF" d="m 24,12 -8.5,6 8.5,6 z M 14,24 V 12 h -2 v 12 z"></path>
</svg>

After

Width:  |  Height:  |  Size: 151 B

@@ -0,0 +1,11 @@
{
inputHash: '735b2a65cb33717b6848f1d17e343908',
outputs: [
{
outputFilePath: 'images/icons/player/previous.png',
outputHash: '4b61ec70865f95fdaf3fd150097e2fd2',
width: 42,
height: 42,
},
],
}