Cast using Youtube app (DIAL/LoungeAPI) (#276)
* Dial+Lounge API PoC * format * Fix for chrome * comments * Rate limit and logger stuff * rename route * remove invalid routes * remove device image * Simplify device description * command test * Lint fix * register pairing code * tv code UI * Lint fix * Avoid creating lots of objects * dpad command * small refactor * tweak * validation * timer * fix * Revert "timer" This reverts commit e349565910882408898c9bddda55dadaa9d743de. * Commands * setVolume command * lounge service timer * Some state messages * Lint fix * player state sync * voice handler * Adjustments, and add a TODO list * Lint fix * comment * play at timestamp * Remote screen UI * UI adjustment * Small refactor * Refactor long polling * Add TODO * Manage logging a bit better to avoid spam in DIAL server * cache dial file * logging * comment * Join lounge lazily * long poller tweak * ui tweak * set shouldQuit field * remote connect notification * Lint fix * Randomize device id, new device on start * Lint fix * Lounge disconnect on start * Speed up lounge by not blocking on sent messages * add version to lounge data saved * dial server fix rendezvous * todo * no message * Display network name * playlist changes * Lint fix * tweak params * tweak * player state * comments * Refactor Video Queue (#295) * Refactor Video Queue * Video queue and playlists * Web app casting * queue playlist notification * VideoQueueView work * restore properties * changes * queue notification and previous/next state * Lint fix * very basic error handling * Update changelog and privacy policy --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
ec9178d687
commit
7d1ba07286
85 files changed
+3666
-938
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import "pkg:/components/Services/LoungeService/LoungeConstants.bs"
|
||||
import "pkg:/components/Services/LoungeService/LoungeMessages.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
namespace Lounge
|
||||
|
||||
function SendNowPlayingLoading(videoId as dynamic) as void
|
||||
if StringUtils.IsNullOrEmpty(m.loungeService.loungeToken)
|
||||
return
|
||||
end if
|
||||
|
||||
overrides = {}
|
||||
overrides[FIELD_STATE] = PlayerState.BUFFERING
|
||||
loungeStateMsg = LoungeMessages.OnStateChange(m.top, overrides)
|
||||
if not StringUtils.IsNullOrEmpty(videoId)
|
||||
overrides[FIELD_VIDEO_ID] = videoId
|
||||
end if
|
||||
nowPlayingMsg = LoungeMessages.NowPlaying(m.top, overrides)
|
||||
m.loungeService.outgoingMessages = [nowPlayingMsg, loungeStateMsg]
|
||||
end function
|
||||
|
||||
function SendOnStateChange() as void
|
||||
if StringUtils.IsNullOrEmpty(m.loungeService.loungeToken)
|
||||
return
|
||||
end if
|
||||
|
||||
loungeStateMsg = LoungeMessages.OnStateChange(m.top)
|
||||
m.loungeService.outgoingMessages = [loungeStateMsg]
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -1,8 +1,9 @@
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/components/Services/Invidious/InvidiousToContentNode.bs"
|
||||
import "pkg:/components/VideoPlayer/Lounge.bs"
|
||||
import "pkg:/components/VideoPlayer/SponsorBlock.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoPlayerStyle.bs"
|
||||
import "pkg:/components/VideoPlayer/VideoUtils.bs"
|
||||
import "pkg:/components/VideoQueue/VideoQueueUtils.bs"
|
||||
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
@@ -70,11 +71,13 @@ function PlayWithContent(contentNode as object)
|
||||
if not StringUtils.IsNullOrEmpty(contentNode.title)
|
||||
videoContentNode.title = contentNode.title
|
||||
end if
|
||||
if not StringUtils.IsNullOrEmpty(contentNode.author)
|
||||
videoContentNode.secondaryTitle = contentNode.author
|
||||
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
|
||||
if not StringUtils.IsNullOrEmpty(contentNode._author)
|
||||
videoContentNode.secondaryTitle = contentNode._author
|
||||
end if
|
||||
|
||||
StartVideoContentTask(videoContentNode)
|
||||
Lounge.SendNowPlayingLoading(contentNode.videoId)
|
||||
end function
|
||||
|
||||
function StartVideoContentTask(videoContentNode as object)
|
||||
@@ -113,7 +116,8 @@ function OnVideoContentTaskResults(output as object) as void
|
||||
message = `Failed to load video information for ${videoId}\n${error}`
|
||||
DialogUtils.ShowDialog(message, "Video load fail", true)
|
||||
' TODO:P1 play next video in the queue after showing the error dialog
|
||||
VideoUtils.CloseVideo()
|
||||
m.videoQueue.closePlayer = true
|
||||
Lounge.SendOnStateChange()
|
||||
return
|
||||
end if
|
||||
|
||||
@@ -161,6 +165,8 @@ function Close(_unused as dynamic)
|
||||
end function
|
||||
|
||||
function OnVideoPlayerStateChange() as void
|
||||
Lounge.SendOnStateChange()
|
||||
|
||||
state = m.top.state
|
||||
content = m.top.content
|
||||
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
|
||||
@@ -227,67 +233,14 @@ function OnVideoPlayerStateChange() as void
|
||||
LogError(title, messageLines)
|
||||
DialogUtils.ShowDialog(messageLines, title, true)
|
||||
' TODO:P1 play next video in the queue after showing the error dialog
|
||||
VideoUtils.CloseVideo()
|
||||
m.videoQueue.closePlayer = true
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnVideoFinished() as void
|
||||
content = m.top.content
|
||||
if content = invalid
|
||||
m.playQueue@.watchedVideosClear()
|
||||
VideoUtils.CloseVideo()
|
||||
return
|
||||
if not VideoQueueUtils.PlayNext(m.videoQueue, m.invidious, m.preferences)
|
||||
m.videoQueue.closePlayer = true
|
||||
end if
|
||||
|
||||
metadata = content.metadata
|
||||
if metadata = invalid
|
||||
m.playQueue@.watchedVideosClear()
|
||||
VideoUtils.CloseVideo()
|
||||
return
|
||||
end if
|
||||
|
||||
if not PlayNext(metadata.recommendedVideos)
|
||||
m.playQueue@.watchedVideosClear()
|
||||
VideoUtils.CloseVideo()
|
||||
end if
|
||||
end function
|
||||
|
||||
function PlayNext(recommendedVideos as object) as boolean
|
||||
if m.playQueue@.PlayNextItem()
|
||||
return true
|
||||
end if
|
||||
|
||||
return PlayNextRecommendedVideo(recommendedVideos)
|
||||
end function
|
||||
|
||||
' TODO:P2 move this to the play queue
|
||||
function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
|
||||
if m.preferences["playback.autoplay"] <> true
|
||||
return false
|
||||
end if
|
||||
|
||||
if recommendedVideos = invalid or recommendedVideos.Count() = 0
|
||||
return false
|
||||
end if
|
||||
|
||||
for each metadata in recommendedVideos
|
||||
if metadata = invalid
|
||||
continue for
|
||||
end if
|
||||
videoId = metadata.videoId
|
||||
if videoId = invalid
|
||||
continue for
|
||||
end if
|
||||
if not m.playQueue@.watchedVideosContain(videoId)
|
||||
LogInfo(`Playing next recommended video (${videoId})`)
|
||||
instance = m.invidious@.GetCurrentInstance()
|
||||
node = InvidiousContent.ToVideoContentNode(invalid, metadata, instance)
|
||||
m.playQueue@.Play(node, -1)
|
||||
return true
|
||||
end if
|
||||
end for
|
||||
|
||||
return false
|
||||
end function
|
||||
|
||||
function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
@@ -298,14 +251,13 @@ function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
' https://community.roku.com/t5/Roku-Developer-Program/Bug-in-10-0-1-Options-key-is-not-being-consumed-by-onKeyEvent-when-Video-node-is-in-focus/m-p/709200/highlight/true#M49312
|
||||
' Because of that, the button "down" is used to shrink the video for picture in picture mode
|
||||
if key = "down"
|
||||
if VideoUtils.ToggleVideoPictureInPicture()
|
||||
if VideoQueueUtils.ToggleVideoPictureInPicture(m.videoQueue)
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
|
||||
if key = "back"
|
||||
m.playQueue@.watchedVideosClear()
|
||||
VideoUtils.CloseVideo()
|
||||
m.videoQueue.closePlayer = true
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<field id="container" type="node" bind=".." />
|
||||
<field id="notifications" type="node" bind="../../Notifications" />
|
||||
<field id="playQueue" type="node" bind="../../PlayQueue" />
|
||||
<field id="videoQueue" type="node" bind="../../VideoQueue" />
|
||||
<field id="preferences" type="node" bind="../../Preferences" />
|
||||
<field id="invidious" type="node" bind="../../Invidious" />
|
||||
<field id="webServer" type="node" bind="../../WebServer" />
|
||||
<field id="loungeService" type="node" bind="../../LoungeService" />
|
||||
<field id="minRect" type="rect2D" value="[834,460,426,240]" />
|
||||
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
|
||||
<field id="chapter" type="string" alias="chapterLabel.text" />
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
namespace VideoUtils
|
||||
function PlayVideo(contentNode as object) as void
|
||||
CloseVideo(false)
|
||||
|
||||
container = GetVideoContainer()
|
||||
' There should be no reason for this to be invalid, but there was a crash report
|
||||
' with this being invalid, so we'll abort playing a video and try to restore focus to the top screen
|
||||
if container = invalid
|
||||
LogError("VideoContainer not found! Attempting to restore focus to top screen...")
|
||||
appController = m.top.getScene().findNode("AppController")
|
||||
if appController <> invalid
|
||||
appController@.FocusTopScreen()
|
||||
end if
|
||||
DialogUtils.ShowDialog(`VideoContainer not found!\nPlease try again. If the problem persist, contact Playlet authors.`, "Error playing video")
|
||||
return
|
||||
end if
|
||||
videoPlayer = container.createChild("videoPlayer")
|
||||
videoPlayer.id = "VideoPlayer"
|
||||
videoPlayer@.BindNode()
|
||||
|
||||
videoPlayer@.PlayWithContent(contentNode)
|
||||
|
||||
if container.fullscreen
|
||||
NodeSetFocus(videoPlayer, true)
|
||||
|
||||
dialog = m.top.getScene().dialog
|
||||
if dialog <> invalid
|
||||
dialog.close = true
|
||||
end if
|
||||
end if
|
||||
end function
|
||||
|
||||
function CloseVideo(setFocus = true as boolean) as void
|
||||
videoPlayer = GetVideoPlayer()
|
||||
if videoPlayer = invalid
|
||||
return
|
||||
end if
|
||||
videoPlayer@.Close()
|
||||
|
||||
if setFocus
|
||||
videoPlayer.appController@.FocusTopScreen()
|
||||
end if
|
||||
end function
|
||||
|
||||
function GetVideoPlayer() as object
|
||||
container = GetVideoContainer()
|
||||
if container = invalid or container.getChildCount() = 0
|
||||
return invalid
|
||||
end if
|
||||
return container.getChild(0)
|
||||
end function
|
||||
|
||||
function GetVideoContainer() as object
|
||||
return m.top.getScene().findNode("VideoContainer")
|
||||
end function
|
||||
|
||||
function IsVideoPlayerFullScreen() as boolean
|
||||
videoContainer = GetVideoContainer()
|
||||
if videoContainer = invalid
|
||||
return false
|
||||
end if
|
||||
return videoContainer.fullscreen
|
||||
end function
|
||||
|
||||
function ToggleVideoPictureInPicture() as boolean
|
||||
videoPlayer = GetVideoPlayer()
|
||||
if videoPlayer = invalid
|
||||
return false
|
||||
end if
|
||||
videoContainer = GetVideoContainer()
|
||||
videoContainer.fullscreen = not videoContainer.fullscreen
|
||||
if videoContainer.fullscreen
|
||||
NodeSetFocus(videoPlayer, true)
|
||||
else
|
||||
videoPlayer.appController@.FocusTopScreen()
|
||||
end if
|
||||
return true
|
||||
end function
|
||||
|
||||
function IsVideoPlayerOpen() as boolean
|
||||
return GetVideoPlayer() <> invalid
|
||||
end function
|
||||
|
||||
function PauseVideo() as boolean
|
||||
player = GetVideoPlayer()
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
player.control = "pause"
|
||||
return true
|
||||
end function
|
||||
|
||||
function ResumeVideo() as boolean
|
||||
player = GetVideoPlayer()
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
player.control = "resume"
|
||||
return true
|
||||
end function
|
||||
|
||||
function TogglePause() as boolean
|
||||
player = GetVideoPlayer()
|
||||
if player = invalid
|
||||
return false
|
||||
end if
|
||||
if player.state = "playing"
|
||||
player.control = "pause"
|
||||
return true
|
||||
else if player.state = "paused"
|
||||
player.control = "resume"
|
||||
return true
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
end namespace
|
||||
|
||||
|
||||
Reference in new issue
Block a user