Fix Issue where auto-play keeps playing the same videos in a loop
This commit is contained in:
1 parent
ae37623756
commit
757bd50701
6 files changed
+74
-5
No files matched your search
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Moved most of Playlet logic to Playlet Lib
|
||||
- Support for multiple caption languages
|
||||
|
||||
#### Fixed
|
||||
- Issue where auto-play keeps playing the same videos in a loop
|
||||
|
||||
## [0.6.0] - 2023-01-10
|
||||
### Added
|
||||
- Ability to clear search history from web app
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import "pkg:/source/utils/RingBuffer.bs"
|
||||
|
||||
function Init()
|
||||
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
|
||||
|
||||
' watchedVideosClear needs at least one arg https://github.com/rokucommunity/brighterscript/blob/master/docs/callfunc-operator.md#callfunc-evaluation-with-no-arguments
|
||||
function watchedVideosClear(unused as dynamic)
|
||||
m.watchedVideos = new RingBuffer(100)
|
||||
end function
|
||||
@@ -5,5 +5,8 @@
|
||||
<field id="videoPlayer" type="node" />
|
||||
<field id="sender" type="node" />
|
||||
<field id="fullscreen" type="boolean" value="true" />
|
||||
<function name="watchedVideosContain" />
|
||||
<function name="watchedVideosAdd" />
|
||||
<function name="watchedVideosClear" />
|
||||
</interface>
|
||||
</component>
|
||||
@@ -38,6 +38,7 @@ function OnkeyEvent(key as string, press as boolean) as boolean
|
||||
end if
|
||||
end if
|
||||
if key = "back"
|
||||
m.videoContainer@.watchedVideosClear()
|
||||
CloseVideo()
|
||||
return true
|
||||
end if
|
||||
@@ -156,6 +157,8 @@ function OnVideoDetailsTaskResults(output as object) as void
|
||||
m.busySpinner.control = "stop"
|
||||
m.top.content = contentNode
|
||||
m.top.control = "play"
|
||||
|
||||
m.videoContainer@.watchedVideosAdd(videoId)
|
||||
end function
|
||||
|
||||
function FindChildNodeOfType(node as object, nodeType as string) as object
|
||||
@@ -277,11 +280,8 @@ function OnVideoPlayerStateChange() as void
|
||||
|
||||
if state = "finished"
|
||||
metadata = m.top.content?.metadata
|
||||
metadata = metadata?.recommendedVideos?.GetEntry(0)
|
||||
videoId = metadata?.videoId
|
||||
if videoId <> invalid
|
||||
PlayVideo(videoId, { metadata: metadata })
|
||||
else
|
||||
|
||||
if not PlayNextRecommendedVideo(metadata?.recommendedVideos)
|
||||
CloseVideo()
|
||||
end if
|
||||
end if
|
||||
@@ -297,6 +297,25 @@ function OnVideoPlayerStateChange() as void
|
||||
end if
|
||||
end function
|
||||
|
||||
function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
|
||||
if recommendedVideos = invalid or recommendedVideos.Count() = 0
|
||||
return false
|
||||
end if
|
||||
|
||||
for each metadata in recommendedVideos
|
||||
videoId = metadata?.videoId
|
||||
if videoId = invalid
|
||||
continue for
|
||||
end if
|
||||
if not m.videoContainer@.watchedVideosContain(videoId)
|
||||
PlayVideo(videoId, { metadata: metadata })
|
||||
return true
|
||||
end if
|
||||
end for
|
||||
|
||||
return false
|
||||
end function
|
||||
|
||||
function SetupAnimation()
|
||||
m.widthAnimation = m.top.findNode("widthAnimation")
|
||||
m.widthAnimationInterpolator = m.top.findNode("widthAnimationInterpolator")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
function GetLocalIpAddress() as string
|
||||
if m.ipAddress = invalid or m.ipAddress = ""
|
||||
di = CreateObject("roDeviceInfo")
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import "pkg:/source/utils/General.bs"
|
||||
|
||||
class RingBuffer
|
||||
private array
|
||||
private size
|
||||
private index
|
||||
|
||||
function new(size as integer)
|
||||
m.array = CreateObject("roArray", size, false)
|
||||
m.size = size
|
||||
m.index = 0
|
||||
end function
|
||||
|
||||
function Push(tvalue As Dynamic)
|
||||
m.array[m.index] = tvalue
|
||||
m.index = (m.index + 1) MOD m.size
|
||||
end function
|
||||
|
||||
function Contains(tvalue As Dynamic) as boolean
|
||||
return ArrayIndexOf(m.array, tvalue) <> -1
|
||||
end function
|
||||
end class
|
||||
Reference in new issue
Block a user