2022-05-21 15:45:38 +00:00
|
|
|
sub init()
|
|
|
|
m.top.optionsAvailable = false
|
2022-05-21 20:45:01 +00:00
|
|
|
|
|
|
|
setupMainNode()
|
|
|
|
setupAudioNode()
|
|
|
|
setupButtons()
|
2022-05-27 01:23:59 +00:00
|
|
|
setupInfoNodes()
|
2022-05-21 20:45:01 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
sub setupMainNode()
|
2022-05-21 15:45:38 +00:00
|
|
|
main = m.top.findNode("toplevel")
|
|
|
|
main.translation = [96, 175]
|
2022-05-21 20:45:01 +00:00
|
|
|
end sub
|
|
|
|
|
|
|
|
sub setupAudioNode()
|
|
|
|
m.top.audio = createObject("RoSGNode", "Audio")
|
|
|
|
m.top.audio.observeField("contentIndex", "audioIndexChanged")
|
|
|
|
end sub
|
2022-05-21 15:45:38 +00:00
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
sub setupButtons()
|
2022-05-21 15:45:38 +00:00
|
|
|
m.buttons = m.top.findNode("buttons")
|
|
|
|
m.buttons.buttons = [tr("Previous"), tr("Play/Pause"), tr("Next")]
|
|
|
|
|
|
|
|
m.buttons.selectedIndex = 1
|
|
|
|
m.buttons.focusedIndex = 1
|
|
|
|
m.buttons.setFocus(true)
|
|
|
|
end sub
|
|
|
|
|
2022-05-27 01:23:59 +00:00
|
|
|
sub setupInfoNodes()
|
|
|
|
m.albumCover = m.top.findNode("albumCover")
|
|
|
|
m.backDrop = m.top.findNode("backdrop")
|
|
|
|
end sub
|
|
|
|
|
2022-05-21 15:45:38 +00:00
|
|
|
sub audioIndexChanged()
|
2022-05-21 20:45:01 +00:00
|
|
|
pageContentChanged()
|
2022-05-21 15:45:38 +00:00
|
|
|
end sub
|
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
function playAction() as boolean
|
2022-05-21 15:45:38 +00:00
|
|
|
if m.top.audio.state = "playing"
|
|
|
|
m.top.audio.control = "pause"
|
|
|
|
else if m.top.audio.state = "paused"
|
|
|
|
m.top.audio.control = "resume"
|
|
|
|
end if
|
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
return true
|
|
|
|
end function
|
|
|
|
|
|
|
|
function previousClicked() as boolean
|
2022-05-21 15:45:38 +00:00
|
|
|
if m.top.audio.contentIndex > 0
|
|
|
|
m.top.audio.nextContentIndex = m.top.audio.contentIndex - 1
|
|
|
|
m.top.audio.control = "skipcontent"
|
|
|
|
end if
|
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
return true
|
|
|
|
end function
|
|
|
|
|
|
|
|
function nextClicked() as boolean
|
2022-05-22 02:04:41 +00:00
|
|
|
if m.top.audio.contentIsPlaylist
|
|
|
|
m.top.audio.control = "skipcontent"
|
|
|
|
end if
|
2022-05-22 12:49:38 +00:00
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
return true
|
|
|
|
end function
|
2022-05-21 15:45:38 +00:00
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
' Update values on screen when page content changes
|
|
|
|
sub pageContentChanged()
|
|
|
|
' If audio isn't playing yet, skip because we have nothing to update
|
2022-05-21 16:05:21 +00:00
|
|
|
if m.top.audio.contentIndex = -1 then return
|
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
item = m.top.pageContent[m.top.audio.contentIndex]
|
2022-05-21 15:45:38 +00:00
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
setPosterImage(item.posterURL)
|
|
|
|
setScreenTitle(item.json)
|
|
|
|
setOnScreenTextValues(item.json)
|
|
|
|
setBackdropImage()
|
|
|
|
end sub
|
2022-05-21 15:45:38 +00:00
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
' Set poster image on screen
|
|
|
|
sub setPosterImage(posterURL)
|
|
|
|
if isValid(posterURL)
|
2022-05-27 01:23:59 +00:00
|
|
|
if m.albumCover.uri <> posterURL
|
|
|
|
m.albumCover.uri = posterURL
|
|
|
|
end if
|
2022-05-21 20:45:01 +00:00
|
|
|
end if
|
|
|
|
end sub
|
2022-05-21 17:33:57 +00:00
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
' Set screen's title text
|
|
|
|
sub setScreenTitle(json)
|
2022-05-22 12:46:53 +00:00
|
|
|
newTitle = ""
|
2022-05-21 20:45:01 +00:00
|
|
|
if isValid(json)
|
2022-05-22 12:46:53 +00:00
|
|
|
if isValid(json.AlbumArtist)
|
|
|
|
newTitle = json.AlbumArtist
|
|
|
|
end if
|
|
|
|
if isValid(json.AlbumArtist) and isValid(json.name)
|
|
|
|
newTitle = newTitle + " / "
|
|
|
|
end if
|
|
|
|
if isValid(json.name)
|
|
|
|
newTitle = newTitle + json.name
|
|
|
|
end if
|
2022-05-21 17:33:57 +00:00
|
|
|
end if
|
2022-05-27 01:23:59 +00:00
|
|
|
|
|
|
|
if m.top.overhangTitle <> newTitle
|
|
|
|
m.top.overhangTitle = newTitle
|
|
|
|
end if
|
2022-05-21 15:45:38 +00:00
|
|
|
end sub
|
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
' Populate on screen text variables
|
|
|
|
sub setOnScreenTextValues(json)
|
|
|
|
if isValid(json)
|
|
|
|
setFieldTextValue("numberofsongs", "Track " + stri(m.top.audio.contentIndex + 1) + "/" + stri(m.top.pageContent.count()))
|
|
|
|
setFieldTextValue("artist", json.Artists[0])
|
|
|
|
setFieldTextValue("album", json.album)
|
|
|
|
setFieldTextValue("song", json.name)
|
2022-05-21 15:45:38 +00:00
|
|
|
end if
|
2022-05-21 20:45:01 +00:00
|
|
|
end sub
|
2022-05-21 15:45:38 +00:00
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
' Add backdrop image to screen
|
|
|
|
sub setBackdropImage()
|
|
|
|
if isValid(m.top.backgroundContent[m.top.audio.contentIndex])
|
2022-05-27 01:23:59 +00:00
|
|
|
if m.backDrop.uri <> m.top.backgroundContent[m.top.audio.contentIndex]
|
|
|
|
m.backDrop.uri = m.top.backgroundContent[m.top.audio.contentIndex]
|
|
|
|
end if
|
2022-05-21 20:45:01 +00:00
|
|
|
end if
|
2022-05-21 15:45:38 +00:00
|
|
|
end sub
|
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
' Process key press events
|
2022-05-21 15:45:38 +00:00
|
|
|
function onKeyEvent(key as string, press as boolean) as boolean
|
|
|
|
|
2022-05-21 20:45:01 +00:00
|
|
|
' Key bindings for remote control buttons
|
|
|
|
if press
|
|
|
|
if key = "play"
|
|
|
|
return playAction()
|
|
|
|
else if key = "back"
|
|
|
|
m.top.audio.control = "stop"
|
|
|
|
else if key = "rewind"
|
|
|
|
return previousClicked()
|
|
|
|
else if key = "fastforward"
|
|
|
|
return nextClicked()
|
|
|
|
end if
|
|
|
|
|
|
|
|
return false
|
|
|
|
end if
|
|
|
|
|
|
|
|
' Key bindings for button group
|
2022-05-27 01:23:59 +00:00
|
|
|
if m.buttons.hasFocus()
|
2022-05-21 20:45:01 +00:00
|
|
|
if key = "OK"
|
|
|
|
if m.buttons.buttons[m.buttons.focusedIndex] = tr("Play/Pause")
|
|
|
|
return playAction()
|
|
|
|
else if m.buttons.buttons[m.buttons.focusedIndex] = tr("Previous")
|
|
|
|
return previousClicked()
|
|
|
|
else if m.buttons.buttons[m.buttons.focusedIndex] = tr("Next")
|
|
|
|
return nextClicked()
|
|
|
|
end if
|
2022-05-21 15:45:38 +00:00
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
return false
|
|
|
|
end function
|