Skip to content

Commit

Permalink
stop loading items to queue if memory is low
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert committed Sep 23, 2023
1 parent ad34a2e commit 06f69f3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
1 change: 1 addition & 0 deletions source/Main.brs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ sub Main (args as dynamic) as void
' - "low" means that the general memory is below acceptable levels but not critical
' - "critical" means that general memory are at dangerously low level and that the OS may force terminate the application
print "event.generalMemoryLevel = ", event.generalMemoryLevel
session.Update("memoreyLevel", event.generalMemoryLevel)
else if isValid(event.audioCodecCapabilityChanged)
' The audio codec capability has changed if true.
print "event.audioCodecCapabilityChanged = ", event.audioCodecCapabilityChanged
Expand Down
69 changes: 45 additions & 24 deletions source/utils/quickplay.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
' All of the Quick Play logic seperated by media type
namespace quickplay

' Takes an array of items and adds to global queue.
' Stop loading items if memory level becomes low
sub pushToQueue(queueArray as object, limitValue = 200 as integer)
if isValidAndNotEmpty(queueArray)
itemCount = queueArray.count()
if limitValue >= itemCount
' load everything
for each item in queueArray
m.global.queueManager.callFunc("push", item)
end for
else
newLimit = limitValue
for i = 0 to itemCount - 1
m.global.queueManager.callFunc("push", queueArray[i])

if i = newLimit
' hit the item limit. check memory level
newLimit = newLimit + limitValue
print "m.global.session.memoryLevel=", m.global.session.memoryLevel
if m.global.session.memoryLevel = "low" or m.global.session.memoryLevel = "critical"
print "Memory is low. Stop loading items in the playlist..."
exit for
end if
end if
end for
end if
end if
end sub

' A single video file.
sub video(itemNode as object)
if not isValid(itemNode) or not isValid(itemNode.id) or not isValid(itemNode.json) then return
Expand Down Expand Up @@ -71,12 +100,13 @@ namespace quickplay
print "artistSongs=", artistSongs

if isValid(artistSongs) and isValidAndNotEmpty(artistSongs.items)
for each artistSong in artistSongs.items
m.global.queueManager.callFunc("push", artistSong)
end for
end if
pushToQueue(artistSongs.items)

m.global.queueManager.callFunc("toggleShuffle")
' don't show shuffle icon for 1 song
if artistSongs.items > 1
m.global.queueManager.callFunc("toggleShuffle")
end if
end if
end sub

' A boxset.
Expand All @@ -91,9 +121,7 @@ namespace quickplay
})
if isValid(data) and isValidAndNotEmpty(data.Items)
' there are videos inside
for each item in data.items
m.global.queueManager.callFunc("push", item)
end for
pushToQueue(data.items)
end if
end sub

Expand Down Expand Up @@ -151,9 +179,7 @@ namespace quickplay

if isValid(data) and isValidAndNotEmpty(data.Items)
' add all episodes found to a playlist
for each item in data.Items
m.global.queueManager.callFunc("push", item)
end for
pushToQueue(data.Items)
end if
end if
end if
Expand Down Expand Up @@ -215,9 +241,7 @@ namespace quickplay
' play the whole season in order
if isValid(unwatchedData) and isValidAndNotEmpty(unwatchedData.Items)
' add all episodes found to a playlist
for each item in unwatchedData.Items
m.global.queueManager.callFunc("push", item)
end for
pushToQueue(unwatchedData.Items)
end if
end if
end if
Expand All @@ -236,9 +260,7 @@ namespace quickplay

if isValid(myPlaylist) and isValidAndNotEmpty(myPlaylist.Items)
' add each item to the queue
for each item in myPlaylist.Items
m.global.queueManager.callFunc("push", item)
end for
pushToQueue(myPlaylist.Items)
m.global.queueManager.callFunc("toggleShuffle")
end if
end sub
Expand Down Expand Up @@ -285,9 +307,7 @@ namespace quickplay
})
print "songsData=", songsData
if isValid(songsData) and isValidAndNotEmpty(songsData.items)
for each song in songsData.Items
m.global.queueManager.callFunc("push", song)
end for
pushToQueue(songsData.Items)
m.global.queueManager.callFunc("toggleShuffle")
end if
else if collectionType = "boxsets"
Expand Down Expand Up @@ -315,9 +335,7 @@ namespace quickplay

if isValid(boxsetData) and isValidAndNotEmpty(boxsetData.items)
' add all boxset items to queue
for each item in boxsetData.items
m.global.queueManager.callFunc("push", item)
end for
pushToQueue(boxsetData.Items)
end if
end if
else if collectionType = "tvshows"
Expand Down Expand Up @@ -396,8 +414,11 @@ namespace quickplay
for each item in playlistItems.items
m.global.queueManager.callFunc("push", item)
end for
' don't show shuffle icon for 1 item
if playlistItems.items > 1
m.global.queueManager.callFunc("toggleShuffle")
end if
end if
m.global.queueManager.callFunc("toggleShuffle")
end if
else
print "Quick Play CollectionFolder WARNING: Unknown collection type"
Expand Down
1 change: 1 addition & 0 deletions source/utils/session.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace session
sub Init()
m.global.addFields({
session: {
"memoryLevel": "normal",
server: {},
user: {
Configuration: {},
Expand Down

0 comments on commit 06f69f3

Please sign in to comment.