(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
@@ -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" />
|
||||
|
||||
Reference in new issue
Block a user