Do not add entire playlist if it already exists
This commit is contained in:
1 parent
7ca98e7ef2
commit
793842f4dd
1 file changed
+38
-3
@@ -190,6 +190,17 @@ function OnPlaylistLoadStateChange() as void
|
||||
end for
|
||||
|
||||
if playlistOp = "play"
|
||||
playlistIndex = MathUtils.Clamp(playlistIndex, 0, videoNodes.Count() - 1)
|
||||
|
||||
' If the playlist is already in the queue as is, play it from there.
|
||||
existingIndex = FindPlaylistVideosInQueue(videoNodes)
|
||||
if existingIndex >= 0
|
||||
m.top.index = existingIndex + playlistIndex
|
||||
m.top.closePlayer = true
|
||||
m.top.play = true
|
||||
return
|
||||
end if
|
||||
|
||||
queueCount = m.content.getChildCount()
|
||||
index = m.top.index
|
||||
index += 1
|
||||
@@ -199,9 +210,7 @@ function OnPlaylistLoadStateChange() as void
|
||||
m.content.insertChildren(videoNodes, index)
|
||||
end if
|
||||
|
||||
playlistIndex = MathUtils.Clamp(playlistIndex, 0, videoNodes.Count() - 1)
|
||||
index = index + playlistIndex
|
||||
m.top.index = index
|
||||
m.top.index = index + playlistIndex
|
||||
|
||||
m.top.closePlayer = true
|
||||
m.top.play = true
|
||||
@@ -217,6 +226,32 @@ function OnPlaylistLoadStateChange() as void
|
||||
end if
|
||||
end function
|
||||
|
||||
function FindPlaylistVideosInQueue(videoNodes as object) as integer
|
||||
queueCount = m.content.getChildCount()
|
||||
playlistCount = videoNodes.Count()
|
||||
if queueCount < playlistCount
|
||||
return -1
|
||||
end if
|
||||
|
||||
queueVideos = m.content.getChildren(-1, 0)
|
||||
|
||||
' array in array search based on node.videoId, starting from the end
|
||||
for i = queueCount - 1 to playlistCount step -1
|
||||
found = true
|
||||
for j = 0 to playlistCount - 1
|
||||
if queueVideos[i - j].videoId <> videoNodes[j].videoId
|
||||
found = false
|
||||
exit for
|
||||
end if
|
||||
end for
|
||||
if found
|
||||
return i - playlistCount + 1
|
||||
end if
|
||||
end for
|
||||
|
||||
return -1
|
||||
end function
|
||||
|
||||
function OnClearQueue()
|
||||
queueCount = m.content.getChildCount()
|
||||
if queueCount > 0
|
||||
|
||||
Reference in new issue
Block a user