Add Now Playing scene
This commit is contained in:
parent
874eedecd7
commit
963aae78d8
|
@ -53,7 +53,7 @@ sub loadItems()
|
|||
url = Substitute("Users/{0}/Items/", get_setting("active_user"))
|
||||
end if
|
||||
resp = APIRequest(url, params)
|
||||
data = getJson(resp)
|
||||
data = getJson(resp)
|
||||
|
||||
if data <> invalid
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<Label id="genres" width="450" height="25" />
|
||||
<Label id="runtime" width="450" height="25" />
|
||||
<Label id="released" width="450" height="25" />
|
||||
<JFButton id="playAlbum" minChars="8" text="Play"></JFButton>
|
||||
<JFButton id="playAlbum" minChars="8" text="Play Album"></JFButton>
|
||||
</LayoutGroup>
|
||||
<LayoutGroup layoutDirection="vert" itemSpacings="[15]">
|
||||
<Label id="overview" wrap="true" width="1250" maxLines="5" />
|
||||
|
|
101
components/music/NowPlaying.brs
Normal file
101
components/music/NowPlaying.brs
Normal file
|
@ -0,0 +1,101 @@
|
|||
sub init()
|
||||
m.top.optionsAvailable = false
|
||||
main = m.top.findNode("toplevel")
|
||||
main.translation = [96, 175]
|
||||
|
||||
m.buttons = m.top.findNode("buttons")
|
||||
m.buttons.buttons = [tr("Previous"), tr("Play/Pause"), tr("Next")]
|
||||
m.buttons.observeField("focusedIndex", "buttonFocusChanged")
|
||||
|
||||
m.buttons.selectedIndex = 1
|
||||
m.buttons.focusedIndex = 1
|
||||
m.buttons.setFocus(true)
|
||||
end sub
|
||||
|
||||
sub audioIndexChanged()
|
||||
itemContentChanged()
|
||||
end sub
|
||||
|
||||
' Switch menu shown when button focus changes
|
||||
sub buttonFocusChanged()
|
||||
if m.buttons.focusedIndex = m.selectedItem then return
|
||||
m.selectedItem = m.buttons.focusedIndex
|
||||
end sub
|
||||
|
||||
sub playClicked()
|
||||
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
|
||||
end sub
|
||||
|
||||
sub previousClicked()
|
||||
if m.top.audio.contentIndex > 0
|
||||
m.top.audio.nextContentIndex = m.top.audio.contentIndex - 1
|
||||
m.top.audio.control = "skipcontent"
|
||||
end if
|
||||
end sub
|
||||
|
||||
sub nextClicked()
|
||||
m.top.audio.control = "skipcontent"
|
||||
end sub
|
||||
|
||||
' Set values for displayed values on screen
|
||||
sub itemContentChanged()
|
||||
item = m.top.itemContent[m.top.audio.contentIndex]
|
||||
|
||||
m.top.findNode("musicartistPoster").uri = item.posterURL
|
||||
m.top.overhangTitle = item.json.AlbumArtist + " / " + item.json.name
|
||||
|
||||
m.top.audio.observeField("contentIndex", "audioIndexChanged")
|
||||
setFieldText("numberofsongs", "Track " + stri(m.top.audio.contentIndex + 1) + "/" + stri(m.top.itemContent.count()))
|
||||
setFieldText("artist", item.json.AlbumArtist)
|
||||
setFieldText("album", item.json.album)
|
||||
setFieldText("song", item.json.name)
|
||||
end sub
|
||||
|
||||
sub setFieldText(field, value)
|
||||
node = m.top.findNode(field)
|
||||
if node = invalid or value = invalid then return
|
||||
|
||||
' Handle non strings... Which _shouldn't_ happen, but hey
|
||||
if type(value) = "roInt" or type(value) = "Integer"
|
||||
value = str(value).trim()
|
||||
else if type(value) = "roFloat" or type(value) = "Float"
|
||||
value = str(value).trim()
|
||||
else if type(value) <> "roString" and type(value) <> "String"
|
||||
value = ""
|
||||
end if
|
||||
|
||||
node.text = value
|
||||
end sub
|
||||
|
||||
function onKeyEvent(key as string, press as boolean) as boolean
|
||||
|
||||
if press and key = "play"
|
||||
playClicked()
|
||||
return true
|
||||
else if press and key = "back"
|
||||
m.top.audio.control = "stop"
|
||||
else if press and key = "rewind"
|
||||
previousClicked()
|
||||
return true
|
||||
else if press and key = "fastforward"
|
||||
nextClicked()
|
||||
return true
|
||||
else if key = "OK" and m.top.findNode("buttons").hasFocus()
|
||||
if m.buttons.buttons[m.selectedItem] = tr("Play/Pause")
|
||||
playClicked()
|
||||
return true
|
||||
else if m.buttons.buttons[m.selectedItem] = tr("Previous")
|
||||
previousClicked()
|
||||
return true
|
||||
else if m.buttons.buttons[m.selectedItem] = tr("Next")
|
||||
nextClicked()
|
||||
return true
|
||||
end if
|
||||
end if
|
||||
|
||||
return false
|
||||
end function
|
30
components/music/NowPlaying.xml
Normal file
30
components/music/NowPlaying.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<component name="NowPlaying" extends="JFGroup">
|
||||
<children>
|
||||
<LayoutGroup id="toplevel" layoutDirection="vert" itemSpacings="[-10]" >
|
||||
<LayoutGroup id="main_group" layoutDirection="horiz" itemSpacings="[15]" >
|
||||
<LayoutGroup layoutDirection="vert" itemSpacings="[15]">
|
||||
<Poster id="musicartistPoster" width="450" height="450" />
|
||||
<Label id="numberofsongs" width="450" height="25" />
|
||||
</LayoutGroup>
|
||||
<LayoutGroup layoutDirection="vert" itemSpacings="[15]">
|
||||
<Label id="artist" width="450" height="25" />
|
||||
<Label id="song" width="450" height="25" />
|
||||
<Label id="album" width="450" height="25" />
|
||||
<MusicAlbumSongList id="songList" itemSize="[ 1250, 60 ]" numRows="8" />
|
||||
<LayoutGroup id="controlButtons" layoutDirection="horiz" itemSpacings="[15]" >
|
||||
<JFButtons id="buttons" />
|
||||
</LayoutGroup>
|
||||
</LayoutGroup>
|
||||
</LayoutGroup>
|
||||
</LayoutGroup>
|
||||
</children>
|
||||
<interface>
|
||||
<field id="itemContent" type="nodearray" onChange="itemContentChanged" />
|
||||
<field id="musicArtistAlbumData" type="assocarray" alias="songList.MusicArtistAlbumData" />
|
||||
<field id="musicSongSelected" alias="songList.itemSelected" />
|
||||
<field id="audio" type="node" />
|
||||
</interface>
|
||||
<script type="text/brightscript" uri="pkg:/source/utils/misc.brs" />
|
||||
<script type="text/brightscript" uri="NowPlaying.brs" />
|
||||
</component>
|
|
@ -416,6 +416,9 @@ end function
|
|||
' Play Audio
|
||||
function CreateAudioPlayerGroup(audiodata)
|
||||
|
||||
group = CreateObject("roSGNode", "NowPlaying")
|
||||
songMetaDataArray = CreateObject("roArray", 0, true)
|
||||
|
||||
if type(audiodata) = "roArray"
|
||||
' Passed data is an array of audio, setup playback as a playlist
|
||||
|
||||
|
@ -428,6 +431,8 @@ function CreateAudioPlayerGroup(audiodata)
|
|||
songContent = audioPlaylistContent.CreateChild("ContentNode")
|
||||
songData = AudioItem(song.id)
|
||||
|
||||
songMetaDataArray.push(ItemMetaData(song.id))
|
||||
|
||||
params = {}
|
||||
|
||||
params.append({
|
||||
|
@ -444,10 +449,6 @@ function CreateAudioPlayerGroup(audiodata)
|
|||
|
||||
m.audio.content = audioPlaylistContent
|
||||
|
||||
m.audio.control = "stop"
|
||||
m.audio.control = "none"
|
||||
m.audio.control = "play"
|
||||
|
||||
else if type(audiodata) = "roSGNode"
|
||||
' Passed data is a single node
|
||||
|
||||
|
@ -459,6 +460,8 @@ function CreateAudioPlayerGroup(audiodata)
|
|||
|
||||
songData = AudioItem(audiodata.id)
|
||||
|
||||
songMetaDataArray.push(ItemMetaData(audiodata.id))
|
||||
|
||||
params = {}
|
||||
|
||||
params.append({
|
||||
|
@ -471,14 +474,20 @@ function CreateAudioPlayerGroup(audiodata)
|
|||
m.audio.content.url = buildURL(Substitute("Audio/{0}/stream", audiodata.id), params)
|
||||
m.audio.content.title = audiodata.title
|
||||
m.audio.content.streamformat = songData.mediaSources[0].container
|
||||
|
||||
m.audio.control = "stop"
|
||||
m.audio.control = "none"
|
||||
m.audio.control = "play"
|
||||
end if
|
||||
end if
|
||||
|
||||
return ""
|
||||
group.musicArtistAlbumData = audiodata
|
||||
group.audio = m.audio
|
||||
group.audio.control = "stop"
|
||||
group.audio.control = "none"
|
||||
group.audio.control = "play"
|
||||
|
||||
group.itemContent = songMetaDataArray
|
||||
|
||||
m.global.sceneManager.callFunc("pushScene", group)
|
||||
|
||||
return group
|
||||
end function
|
||||
|
||||
function CreatePersonView(personData as object) as object
|
||||
|
|
|
@ -211,7 +211,7 @@ function AudioItem(id as string)
|
|||
tmp.json = data
|
||||
results.push(tmp)
|
||||
end if
|
||||
|
||||
|
||||
data.Items = results
|
||||
return data
|
||||
end function
|
||||
|
|
Loading…
Reference in New Issue
Block a user