(Regression) Fix issue where auto-play keeps playing the same videos in a loop
This commit is contained in:
1 parent
49be599c32
commit
2ba2115da7
6 files changed
+32
-34
No files matched your search
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- (Regression) Issue where auto-play keeps playing the same videos in a loop
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
- Xmas theme logo - can't publish it before end of year... ([link](https://blog.roku.com/developer/channel-store-blackouts-2023))
|
- Xmas theme logo - can't publish it before end of year... ([link](https://blog.roku.com/developer/channel-store-blackouts-2023))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import "pkg:/source/asyncTask/asyncTask.bs"
|
|||||||
import "pkg:/source/utils/ArrayUtils.bs"
|
import "pkg:/source/utils/ArrayUtils.bs"
|
||||||
import "pkg:/source/utils/ErrorUtils.bs"
|
import "pkg:/source/utils/ErrorUtils.bs"
|
||||||
import "pkg:/source/utils/Logging.bs"
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
import "pkg:/source/utils/RingBuffer.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
|
|
||||||
' TODO:P1 prevent adding duplicates of the same video/playlist
|
' TODO:P1 prevent adding duplicates of the same video/playlist
|
||||||
@@ -17,6 +18,8 @@ function Init()
|
|||||||
m.top.content = m.content
|
m.top.content = m.content
|
||||||
m.content.addField("index", "integer", false)
|
m.content.addField("index", "integer", false)
|
||||||
m.content.index = m.top.index
|
m.content.index = m.top.index
|
||||||
|
' TODO:P2 use actual queue nodes instead of internal buffer
|
||||||
|
m.watchedVideos = new RingBuffer(100)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function Play(node as object, playlistIndex as integer)
|
function Play(node as object, playlistIndex as integer)
|
||||||
@@ -138,7 +141,7 @@ function PlayItemAtCurrentIndex() as boolean
|
|||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
if node.type = "video"
|
if node.type = "video"
|
||||||
VideoUtils.PlayVideo(node)
|
PlayVideo(node)
|
||||||
return true
|
return true
|
||||||
else if node.type = "playlist"
|
else if node.type = "playlist"
|
||||||
if m.top.playlistIndex = -1
|
if m.top.playlistIndex = -1
|
||||||
@@ -162,7 +165,7 @@ function PlayPlaylistAtCurrentIndex(playlist as object) as boolean
|
|||||||
|
|
||||||
if playlistIndex < playlist.getChildCount()
|
if playlistIndex < playlist.getChildCount()
|
||||||
child = playlist.getChild(playlistIndex)
|
child = playlist.getChild(playlistIndex)
|
||||||
VideoUtils.PlayVideo(child)
|
PlayVideo(child)
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -170,6 +173,14 @@ function PlayPlaylistAtCurrentIndex(playlist as object) as boolean
|
|||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function PlayVideo(node as object)
|
||||||
|
videoId = node.videoId
|
||||||
|
if not m.watchedVideos.Contains(videoId)
|
||||||
|
m.watchedVideos.Push(videoId)
|
||||||
|
end if
|
||||||
|
VideoUtils.PlayVideo(node)
|
||||||
|
end function
|
||||||
|
|
||||||
function LoadPlaylist(playlist as object) as void
|
function LoadPlaylist(playlist as object) as void
|
||||||
if playlist.loadState = FeedLoadState.Loading
|
if playlist.loadState = FeedLoadState.Loading
|
||||||
return
|
return
|
||||||
@@ -219,3 +230,11 @@ function OnIndexChange()
|
|||||||
child.index = index
|
child.index = index
|
||||||
end for
|
end for
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function watchedVideosContain(videoId as string) as boolean
|
||||||
|
return m.watchedVideos.Contains(videoId)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function watchedVideosClear(unused as dynamic)
|
||||||
|
m.watchedVideos = new RingBuffer(100)
|
||||||
|
end function
|
||||||
@@ -12,6 +12,8 @@
|
|||||||
<function name="Clear" />
|
<function name="Clear" />
|
||||||
<function name="PlayNextItem" />
|
<function name="PlayNextItem" />
|
||||||
<function name="PlayItemAtIndex" />
|
<function name="PlayItemAtIndex" />
|
||||||
|
<function name="watchedVideosContain" />
|
||||||
|
<function name="watchedVideosClear" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
<ContentNode id="Content" />
|
<ContentNode id="Content" />
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import "pkg:/source/utils/RingBuffer.bs"
|
|
||||||
|
|
||||||
function Init()
|
|
||||||
' We keep in memory the last videos we watched, to avoid a loop
|
|
||||||
' Sometimes recommended videos point to each other, and we're stuck watching
|
|
||||||
' The same 2 videos over and over again
|
|
||||||
|
|
||||||
' TODO:P1 get rid of `watchedVideos` and use the PlayQueue instead
|
|
||||||
m.watchedVideos = new RingBuffer(100)
|
|
||||||
end function
|
|
||||||
|
|
||||||
function watchedVideosContain(videoId as string) as boolean
|
|
||||||
return m.watchedVideos.Contains(videoId)
|
|
||||||
end function
|
|
||||||
|
|
||||||
function watchedVideosAdd(videoId as string)
|
|
||||||
if not watchedVideosContain(videoId)
|
|
||||||
m.watchedVideos.Push(videoId)
|
|
||||||
end if
|
|
||||||
end function
|
|
||||||
|
|
||||||
function watchedVideosClear(unused as dynamic)
|
|
||||||
m.watchedVideos = new RingBuffer(100)
|
|
||||||
end function
|
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
<component name="VideoContainer" extends="Group">
|
<component name="VideoContainer" extends="Group">
|
||||||
<interface>
|
<interface>
|
||||||
<field id="fullscreen" type="boolean" value="true" />
|
<field id="fullscreen" type="boolean" value="true" />
|
||||||
<function name="watchedVideosContain" />
|
|
||||||
<function name="watchedVideosAdd" />
|
|
||||||
<function name="watchedVideosClear" />
|
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -186,20 +186,20 @@ function OnVideoPlayerStateChange() as void
|
|||||||
|
|
||||||
if state = "finished"
|
if state = "finished"
|
||||||
if content = invalid
|
if content = invalid
|
||||||
m.container@.watchedVideosClear()
|
m.playQueue@.watchedVideosClear()
|
||||||
VideoUtils.CloseVideo()
|
VideoUtils.CloseVideo()
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
metadata = content.metadata
|
metadata = content.metadata
|
||||||
if metadata = invalid
|
if metadata = invalid
|
||||||
m.container@.watchedVideosClear()
|
m.playQueue@.watchedVideosClear()
|
||||||
VideoUtils.CloseVideo()
|
VideoUtils.CloseVideo()
|
||||||
return
|
return
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if not PlayNext(metadata.recommendedVideos)
|
if not PlayNext(metadata.recommendedVideos)
|
||||||
m.container@.watchedVideosClear()
|
m.playQueue@.watchedVideosClear()
|
||||||
VideoUtils.CloseVideo()
|
VideoUtils.CloseVideo()
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
@@ -251,7 +251,7 @@ function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
|
|||||||
if videoId = invalid
|
if videoId = invalid
|
||||||
continue for
|
continue for
|
||||||
end if
|
end if
|
||||||
if not m.container@.watchedVideosContain(videoId)
|
if not m.playQueue@.watchedVideosContain(videoId)
|
||||||
LogInfo(`Playing next recommended video (${videoId})`)
|
LogInfo(`Playing next recommended video (${videoId})`)
|
||||||
instance = m.invidious@.GetCurrentInstance()
|
instance = m.invidious@.GetCurrentInstance()
|
||||||
node = InvidiousContent.ToVideoContentNode(invalid, metadata, instance)
|
node = InvidiousContent.ToVideoContentNode(invalid, metadata, instance)
|
||||||
@@ -277,7 +277,7 @@ function OnkeyEvent(key as string, press as boolean) as boolean
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
if key = "back"
|
if key = "back"
|
||||||
m.container@.watchedVideosClear()
|
m.playQueue@.watchedVideosClear()
|
||||||
VideoUtils.CloseVideo()
|
VideoUtils.CloseVideo()
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|||||||
Reference in new issue
Block a user