Dev video player (#321)
This commit is contained in:
1 parent
f71ad7b873
commit
7bb73e0fb6
8 files changed
+196
-13
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
|
||||
@asynctask
|
||||
function VideoContentTaskDev(input as object) as object
|
||||
contentNode = input.content
|
||||
invidiousNode = input.invidious
|
||||
|
||||
if StringUtils.IsNullOrEmpty(contentNode.videoId)
|
||||
throw "Can't load video information: videoId is missing"
|
||||
end if
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
|
||||
response = service.GetVideoMetadata(contentNode.videoId, { cancellation: m.top.cancellation })
|
||||
|
||||
if m.top.cancel
|
||||
return invalid
|
||||
end if
|
||||
|
||||
metadata = response.Json()
|
||||
|
||||
if not response.IsSuccess() or metadata = invalid
|
||||
return {
|
||||
success: false
|
||||
error: response.ErrorMessage()
|
||||
}
|
||||
end if
|
||||
|
||||
contentNode.title = metadata.title
|
||||
contentNode.secondaryTitle = metadata.author
|
||||
contentNode.live = metadata.liveNow
|
||||
|
||||
streamUrls = [`http://127.0.0.1:8888/api/dash?v=${metadata.videoId}`]
|
||||
contentNode.url = streamUrls[0]
|
||||
|
||||
contentNode.addFields({
|
||||
metadata: metadata
|
||||
' StreamUrls is taken
|
||||
playletStreamUrls: streamUrls
|
||||
playletStreamUrlIndex: 0
|
||||
})
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
end function
|
||||
@@ -0,0 +1,95 @@
|
||||
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
|
||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/source/utils/Logging.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
m.top.enableUI = false
|
||||
m.top.enableTrickPlay = false
|
||||
|
||||
httpAgent = m.top.getHttpAgent()
|
||||
httpAgent.AddHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0")
|
||||
end function
|
||||
|
||||
function PlayWithContent(contentNode as object)
|
||||
videoContentNode = CreateObject("roSGNode", "ContentNode")
|
||||
|
||||
if not StringUtils.IsNullOrEmpty(contentNode.videoId)
|
||||
videoContentNode.AddFields({ videoId: contentNode.videoId })
|
||||
end if
|
||||
if not StringUtils.IsNullOrEmpty(contentNode.title)
|
||||
videoContentNode.title = contentNode.title
|
||||
end if
|
||||
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
|
||||
if not StringUtils.IsNullOrEmpty(contentNode._author)
|
||||
videoContentNode.secondaryTitle = contentNode._author
|
||||
end if
|
||||
|
||||
StartVideoContentTask(videoContentNode)
|
||||
end function
|
||||
|
||||
function StartVideoContentTask(videoContentNode as object)
|
||||
if m.videoContentTask <> invalid
|
||||
m.videoContentTask.cancel = true
|
||||
end if
|
||||
|
||||
m.top.content = videoContentNode
|
||||
|
||||
m.videoContentTask = AsyncTask.Start(Tasks.VideoContentTaskDev, {
|
||||
content: videoContentNode
|
||||
invidious: m.top.invidious
|
||||
}, OnVideoContentTaskResults)
|
||||
end function
|
||||
|
||||
function OnVideoContentTaskResults(output as object) as void
|
||||
m.videoContentTask = invalid
|
||||
if output.cancelled
|
||||
return
|
||||
end if
|
||||
|
||||
if not output.success or not output.result.success
|
||||
' output.error for unhandled exception
|
||||
error = output.error
|
||||
if error = invalid
|
||||
' output.result.error for network errors
|
||||
error = output.result.error
|
||||
end if
|
||||
error = ErrorUtils.Format(error)
|
||||
LogError(error)
|
||||
Close(invalid)
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.control = "play"
|
||||
end function
|
||||
|
||||
function Close(_unused as dynamic)
|
||||
if m.videoContentTask <> invalid
|
||||
m.videoContentTask.cancel = true
|
||||
m.videoContentTask = invalid
|
||||
end if
|
||||
|
||||
parent = m.top.getParent()
|
||||
if parent <> invalid
|
||||
parent.RemoveChild(m.top)
|
||||
end if
|
||||
|
||||
m.top.control = "stop"
|
||||
m.top.content = invalid
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
if press = false
|
||||
return false
|
||||
end if
|
||||
|
||||
if key = "back"
|
||||
m.videoQueue.closePlayer = true
|
||||
return true
|
||||
end if
|
||||
|
||||
return false
|
||||
end function
|
||||
@@ -0,0 +1,23 @@
|
||||
<!--
|
||||
VideoPlayerDev is the player that will eventually be used in the Playlet app.
|
||||
It extends the Video component, and will be fully managing the UI, progress,
|
||||
buffering, and any state of the video playback.
|
||||
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">
|
||||
<interface>
|
||||
<field id="videoQueue" type="node" bind="../../VideoQueue" />
|
||||
<field id="invidious" type="node" bind="../../Invidious" />
|
||||
<function name="PlayWithContent" />
|
||||
<function name="Close" />
|
||||
</interface>
|
||||
<children>
|
||||
<SimpleLabel
|
||||
text="Dev Player!"
|
||||
color="#FF0000"
|
||||
fontUri="font:SmallestBoldSystemFont"
|
||||
horizOrigin="right"
|
||||
translation="[1280,0]" />
|
||||
</children>
|
||||
</component>
|
||||
@@ -355,8 +355,15 @@ function OnHasNext()
|
||||
end function
|
||||
|
||||
function CreateVideoPlayer() as object
|
||||
useDevPlayer = m.top.preferences["dev.dev_video_player"]
|
||||
if useDevPlayer
|
||||
playerComponent = "VideoPlayerDev"
|
||||
else
|
||||
playerComponent = "VideoPlayer"
|
||||
end if
|
||||
|
||||
container = m.top.videoContainer
|
||||
videoPlayer = container.createChild("VideoPlayer")
|
||||
videoPlayer = container.createChild(playerComponent)
|
||||
videoPlayer.id = "VideoPlayer"
|
||||
videoPlayer@.BindNode()
|
||||
|
||||
|
||||
@@ -188,4 +188,25 @@
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayText: "Developer",
|
||||
key: "dev",
|
||||
description: "Developer preferences",
|
||||
children: [
|
||||
{
|
||||
displayText: "Use dev video player",
|
||||
key: "dev.dev_video_player",
|
||||
description: "Enable the dev video player. This is an unfinished video player for testing purposes.",
|
||||
type: "boolean",
|
||||
defaultValue: false,
|
||||
},
|
||||
{
|
||||
displayText: "Playlet Library version",
|
||||
key: "dev.playlet_lib_version",
|
||||
description: "The version of Playlet Lib to use. These correspond to tagged releases on Github. Releases that do not have a playlet-lib.zip file are disabled.",
|
||||
visibility: "web",
|
||||
svelteComponent: "PlayletLibVersionControl",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
Reference in new issue
Block a user