(Regression) Fix issue where auto-play keeps playing the same videos in a loop

This commit is contained in:
Brahim Hadriche committed 2023-12-15 21:27:41 -05:00
1 parent 49be599c32
commit 2ba2115da7
6 files changed
+32 -34

No files matched your search

+4
View File
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- (Regression) Issue where auto-play keeps playing the same videos in a loop
### Removed
- 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/ErrorUtils.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RingBuffer.bs"
import "pkg:/source/utils/Types.bs"
' TODO:P1 prevent adding duplicates of the same video/playlist
@@ -17,6 +18,8 @@ function Init()
m.top.content = m.content
m.content.addField("index", "integer", false)
m.content.index = m.top.index
' TODO:P2 use actual queue nodes instead of internal buffer
m.watchedVideos = new RingBuffer(100)
end function
function Play(node as object, playlistIndex as integer)
@@ -138,7 +141,7 @@ function PlayItemAtCurrentIndex() as boolean
return false
end if
if node.type = "video"
VideoUtils.PlayVideo(node)
PlayVideo(node)
return true
else if node.type = "playlist"
if m.top.playlistIndex = -1
@@ -162,7 +165,7 @@ function PlayPlaylistAtCurrentIndex(playlist as object) as boolean
if playlistIndex < playlist.getChildCount()
child = playlist.getChild(playlistIndex)
VideoUtils.PlayVideo(child)
PlayVideo(child)
return true
end if
@@ -170,6 +173,14 @@ function PlayPlaylistAtCurrentIndex(playlist as object) as boolean
return true
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
if playlist.loadState = FeedLoadState.Loading
return
@@ -219,3 +230,11 @@ function OnIndexChange()
child.index = index
end for
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="PlayNextItem" />
<function name="PlayItemAtIndex" />
<function name="watchedVideosContain" />
<function name="watchedVideosClear" />
</interface>
<children>
<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">
<interface>
<field id="fullscreen" type="boolean" value="true" />
<function name="watchedVideosContain" />
<function name="watchedVideosAdd" />
<function name="watchedVideosClear" />
</interface>
</component>
@@ -186,20 +186,20 @@ function OnVideoPlayerStateChange() as void
if state = "finished"
if content = invalid
m.container@.watchedVideosClear()
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
return
end if
metadata = content.metadata
if metadata = invalid
m.container@.watchedVideosClear()
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
return
end if
if not PlayNext(metadata.recommendedVideos)
m.container@.watchedVideosClear()
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
end if
end if
@@ -251,7 +251,7 @@ function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
if videoId = invalid
continue for
end if
if not m.container@.watchedVideosContain(videoId)
if not m.playQueue@.watchedVideosContain(videoId)
LogInfo(`Playing next recommended video (${videoId})`)
instance = m.invidious@.GetCurrentInstance()
node = InvidiousContent.ToVideoContentNode(invalid, metadata, instance)
@@ -277,7 +277,7 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end if
if key = "back"
m.container@.watchedVideosClear()
m.playQueue@.watchedVideosClear()
VideoUtils.CloseVideo()
return true
end if