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