Skip to content

Commit

Permalink
If current and next item are both audio, don't leave player
Browse files Browse the repository at this point in the history
  • Loading branch information
1hitsong committed Feb 23, 2024
1 parent d9f7146 commit 39abf06
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
4 changes: 4 additions & 0 deletions components/manager/QueueManager.bs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ sub setTopStartingPoint(positionTicks)
m.queue[0].startingPoint = positionTicks
end sub

' getItemType: Returns the media type of the passed item
'
' @param {dynamic} item - Item to evaluate
' @return {string} indicating type of media item is
function getItemType(item) as string
if isValid(item) and isValid(item.json) and isValid(item.json.mediatype) and item.json.mediatype <> ""
return LCase(item.json.mediatype)
Expand Down
1 change: 1 addition & 0 deletions components/manager/QueueManager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<function name="getHold" />
<function name="getIsShuffled" />
<function name="getItemByIndex" />
<function name="getItemType" />
<function name="getPosition" />
<function name="getQueue" />
<function name="getQueueTypes" />
Expand Down
38 changes: 26 additions & 12 deletions components/music/AudioPlayerView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,22 @@ function playAction() as boolean
end function

function previousClicked() as boolean
if m.global.queueManager.callFunc("getPosition") = 0 then return false
currentQueuePosition = m.global.queueManager.callFunc("getPosition")

if currentQueuePosition = 0 then return false

if m.playlistTypeCount > 1
m.global.audioPlayer.control = "stop"
previousItem = m.global.queueManager.callFunc("getItemByIndex", currentQueuePosition - 1)
previousItemType = m.global.queueManager.callFunc("getItemType", previousItem)

m.global.sceneManager.callFunc("clearPreviousScene")
m.global.queueManager.callFunc("moveBack")
m.global.queueManager.callFunc("playQueue")
return true
if previousItemType <> "audio"
m.global.audioPlayer.control = "stop"

m.global.sceneManager.callFunc("clearPreviousScene")
m.global.queueManager.callFunc("moveBack")
m.global.queueManager.callFunc("playQueue")
return true
end if
end if

exitScrubMode()
Expand Down Expand Up @@ -362,14 +369,21 @@ end sub

function nextClicked() as boolean
if m.playlistTypeCount > 1
if m.global.queueManager.callFunc("getPosition") < m.global.queueManager.callFunc("getCount") - 1
m.global.audioPlayer.control = "stop"
currentQueuePosition = m.global.queueManager.callFunc("getPosition")
if currentQueuePosition < m.global.queueManager.callFunc("getCount") - 1

m.global.sceneManager.callFunc("clearPreviousScene")
m.global.queueManager.callFunc("moveForward")
m.global.queueManager.callFunc("playQueue")
nextItem = m.global.queueManager.callFunc("getItemByIndex", currentQueuePosition + 1)
nextItemType = m.global.queueManager.callFunc("getItemType", nextItem)

if nextItemType <> "audio"
m.global.audioPlayer.control = "stop"

m.global.sceneManager.callFunc("clearPreviousScene")
m.global.queueManager.callFunc("moveForward")
m.global.queueManager.callFunc("playQueue")
return true
end if
end if
return true
end if

exitScrubMode()
Expand Down

0 comments on commit 39abf06

Please sign in to comment.