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()
|
|
|
|
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
|
|
|
|
|
|
|
|
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-21 15:45:38 +00:00
|
|
|
m.top.audio.control = "skipcontent"
|
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)
|
|
|
|
m.top.findNode("albumCover").uri = posterURL
|
|
|
|
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)
|
|
|
|
if isValid(json)
|
|
|
|
m.top.overhangTitle = json.AlbumArtist + " / " + json.name
|
2022-05-21 17:33:57 +00:00
|
|
|
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])
|
|
|
|
m.top.findNode("backdrop").uri = m.top.backgroundContent[m.top.audio.contentIndex]
|
|
|
|
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
|
|
|
|
if m.top.findNode("buttons").hasFocus()
|
|
|
|
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
|