This is my contribution for randomizing videos applied to the function LOOP ALL (Now mean: LOOP ALL RANDOMIZING). The patch will be applied only to the client side application, appMain.brs).
Any comments are appreciated.
Function buildVideoContent(vids as Object, posters as object, all as Boolean) as Integer
' Removes any sub-directories and other non-videos from the 'posters' list and builds
' an array of videos to be passed to the roVideoScreen component
print "buildVideoContent"
maxidx = posters.Count() - 1
numvid = 0
'***
'*** new code for randomizing videos sequence
'***
first = Rnd(maxidx)
print "Num. Elements: " + toStr(maxidx)
slidesorder = GenerateMediaOrder(maxidx, first, True)
numslides = slidesorder.Count()
For i = 1 To numslides
print "index: " ToStr(i) + "-" + ToStr(slidesorder[i])
item = posters[i].item
print "video: " item.GetTitle()
print "--"
End For
y = 0
For x = 0 To maxidx
y = slidesorder[x]
If y <= maxidx Then
i = slidesorder[x]
item = posters[i].item
If item.GetContentType() = "movie" And Not item.GetStreamFormat() = "hls" Then
If all Or Not Left(posters[i].ShortDescriptionLine2,5) = "Watch" Then
vid = item.GetPlayable()
vid.index = i
numvid = numvid + 1
vids.Push(vid)
End If
End If
End If
End For
return numvid
'***
'*** end new code
'***
'***
'*** original (commented) old code
'***
' for i = 2 to maxidx ' skip Playall posters
' item = posters[i].item
' if item.GetContentType() = "movie" and not item.GetStreamFormat() = "hls" then
' if all or not Left(posters[i].ShortDescriptionLine2,5) = "Watch" then
' vid = item.GetPlayable()
' vid.index = i
' numvid = numvid + 1
' vids.Push(vid)
' end if
' end if
' end for
' return numvid
End Function
'****
'**** New routine added to the source
'****
' generate an array of indexes to use for accessing media in the order specified
' index is what we want the first one to be.
' israndom tells us to randomize the rest of the slots
Function GenerateMediaOrder(count, index, israndom)
print "GenerateMediaOrder"
slideorder = [count]
i = 0
while i < count-index
slideorder[i] = i+index
i = i+1
end while
while i < count
slideorder[i] = i - (count-index)
i = i+1
end while
if israndom
' now shuffle them up, except for the first one
i = 1
while i < count
newpos = rnd(count-1)
oldval = slideorder[newpos]
slideorder[newpos] = slideorder[i]
slideorder[i] = oldval
i = i+1
end while
endif
return slideorder
end Function