diff --git a/src/components/HomeGridScreen/HomeGridScreen.bs b/src/components/HomeGridScreen/HomeGridScreen.bs index 12e548e9..cbaadb39 100644 --- a/src/components/HomeGridScreen/HomeGridScreen.bs +++ b/src/components/HomeGridScreen/HomeGridScreen.bs @@ -46,8 +46,6 @@ function StartFetchTask() as void if m.sortedContent.Count() = m.defaultLayout.Count() ' All tasks are done m.Delete("sortedContent") - ' TODO: uncommment if auto-play - ' m.top.ObserveField("rowItemFocused", "OnHomeGridScreenVideoFocused") end if return end if @@ -108,19 +106,8 @@ function OnHomeGridScreenVideoSelected(event as object) as void videoId = itemContent.videoId - if m.videoPlayer <> invalid - if m.videoPlayer.videoId = videoId - ExpandVideoScreenFull() - return - else - m.videoPlayer.control = "stop" - m.videoPlayer.visible = false - m.videoPlayer.getParent().removeChild(m.videoPlayer) - m.videoPlayer = invalid - end if - end if - - ShowVideoScreenFull(videoId, m.top) + CloseVideo() + ShowVideoScreen(videoId, m.top) end function function CloseVideo() @@ -135,39 +122,7 @@ end function function OnPlayVideoCommand() videoId = m.top.playvideo CloseVideo() - ShowVideoScreenFull(videoId, m.top) -end function - -function OnHomeGridScreenVideoFocused(event as object) as void - if m.videoPlayer <> invalid - m.videoPlayer.control = "stop" - m.videoPlayer.visible = false - m.videoPlayer.getParent().removeChild(m.videoPlayer) - m.videoPlayer = invalid - end if - grid = event.GetRoSGNode() - - selectedPair = event.GetData() - selectedRow = selectedPair[0] - selectedRowItem = selectedPair[1] - - rowContent = grid.content.GetChild(selectedRow) - itemContent = rowContent.GetChild(selectedRowItem) - - videoId = itemContent.videoId - thumbnail = GetThumbnailPoster(videoId) - ShowVideoScreenEmbedded(videoId, thumbnail) -end function - -function GetThumbnailPoster(videoId as string) as object - ' TODO: make this faster - all = m.top.getAll() - for each item in all - if item.id = `thumbnail-${videoId}` - return item - end if - end for - return invalid + ShowVideoScreen(videoId, m.top) end function function OnkeyEvent(key as string, press as boolean) as boolean diff --git a/src/components/SearchScreen/SearchScreen.bs b/src/components/SearchScreen/SearchScreen.bs index 99147889..c328ad78 100644 --- a/src/components/SearchScreen/SearchScreen.bs +++ b/src/components/SearchScreen/SearchScreen.bs @@ -127,7 +127,7 @@ function OnSearchVideoSelected(event as object) itemContent = rowContent.GetChild(selectedRowItem) videoId = itemContent.videoId - ShowVideoScreenFull(videoId, m.top) + ShowVideoScreen(videoId, m.top) end function function OnkeyEvent(key as string, press as boolean) as boolean diff --git a/src/components/VideoPlayer/Video.bs b/src/components/VideoPlayer/Video.bs index f01b71e7..19289021 100644 --- a/src/components/VideoPlayer/Video.bs +++ b/src/components/VideoPlayer/Video.bs @@ -1,66 +1,28 @@ import "pkg:/source/services/Invidious.bs" -function ShowVideoScreenEmbedded(videoId as string, thumbnailNode as object) - m.videoPlayer = CreateObject("roSGNode", "VideoPlayer") - AddVideoFields() - m.videoPlayer.embedded = true - - m.videoPlayer.enableUI = false - m.videoPlayer.width = thumbnailNode.width - m.videoPlayer.height = thumbnailNode.height - thumbnailNode.AppendChild(m.videoPlayer) - ShowVideoScreen(videoId) -end function - -function ShowVideoScreenFull(videoId as string, sender as object) +function ShowVideoScreen(videoId as string, sender as object) m.videoPlayer = CreateObject("roSGNode", "VideoPlayer") m.videoPlayer.sender = sender - AddVideoFields() - m.videoPlayer.embedded = false - - ' TODO: make sure video is at right node - m.top.getParent().AppendChild(m.videoPlayer) - ShowVideoScreen(videoId) -end function - -function AddVideoFields() m.videoPlayer.addFields({ - embedded: false, sponsorBlockTask: false, videoPlayingSuccess: false, - ignoreNextFinishedState: false + ignoreNextFinishedState: false, + videoId: videoId }) -end function -function ExpandVideoScreenFull() - m.videoPlayer.embedded = true - m.videoPlayer.reparent(m.top, false) - m.videoPlayer.enableUI = true - m.videoPlayer.width = 1280 - m.videoPlayer.height = 720 - m.videoPlayer.SetFocus(true) - StartSponsorBlockTask(m.videoPlayer.videoId) -end function + m.videoPlayer.getScene().AppendChild(m.videoPlayer) -function ShowVideoScreen(videoId as string) - m.videoPlayer.addFields({ videoId: videoId }) m.videoPlayer.trickPlayBar.filledBarBlendColor = "0xFF0000FF" m.videoPlayer.bufferingBar.filledBarBlendColor = "0xFF0000FF" m.videoPlayer.retrievingBar.filledBarBlendColor = "0xFF0000FF" - if not m.videoPlayer.embedded - m.videoPlayer.visible = true - m.videoPlayer.SetFocus(true) - else - m.videoPlayer.visible = false - end if + m.videoPlayer.visible = true + m.videoPlayer.SetFocus(true) m.videoPlayer.ObserveField("state", "OnVideoPlayerStateChange") StartVideoDetailsTask(videoId) - if not m.videoPlayer.embedded - StartSponsorBlockTask(videoId) - end if + StartSponsorBlockTask(videoId) end function function OnVideoPlayerStateChange() as void @@ -112,11 +74,12 @@ function OnVideoPlayerStateChange() as void end function function CloseVideoPlayer() + sender = m.videoPlayer.sender m.videoPlayer.control = "stop" m.videoPlayer.visible = false m.videoPlayer.getParent().RemoveChild(m.videoPlayer) m.videoPlayer = invalid - m.top.focus = true + sender.focus = true end function function StartVideoDetailsTask(videoId as string)