Play song when selected
This commit is contained in:
parent
183ada1f5c
commit
158b7623ba
|
@ -158,6 +158,8 @@ sub Main (args as dynamic) as void
|
|||
group = CreateMusicArtistDetailsGroup(selectedItem.json)
|
||||
else if selectedItem.type = "MusicAlbum"
|
||||
group = CreateMusicAlbumDetailsGroup(selectedItem.json)
|
||||
else if selectedItem.type = "Audio"
|
||||
group = CreateAudioPlayerGroup(selectedItem.json)
|
||||
else
|
||||
' TODO - switch on more node types
|
||||
message_dialog("This type is not yet supported: " + selectedItem.type + ".")
|
||||
|
@ -185,10 +187,10 @@ sub Main (args as dynamic) as void
|
|||
node = albums.musicArtistAlbumData.items[ptr[1]]
|
||||
group = CreateMusicAlbumDetailsGroup(node)
|
||||
else if isNodeEvent(msg, "musicSongSelected")
|
||||
|
||||
' Enjoy the silence
|
||||
message_dialog("Playing songs is not yet supported.")
|
||||
|
||||
' If you select a Song from ANYWHERE, follow this flow
|
||||
selectedIndex = msg.getData()
|
||||
songs = msg.getRoSGNode()
|
||||
group = CreateAudioPlayerGroup(songs.MusicArtistAlbumData.items[selectedIndex])
|
||||
else if isNodeEvent(msg, "episodeSelected")
|
||||
' If you select a TV Episode from ANYWHERE, follow this flow
|
||||
node = getMsgPicker(msg, "picker")
|
||||
|
|
|
@ -342,6 +342,7 @@ function CreateMusicAlbumDetailsGroup(album)
|
|||
group.itemContent = ItemMetaData(album.id)
|
||||
group.musicArtistAlbumData = MusicSongList(album.id)
|
||||
|
||||
' Watch for user clicking on a song
|
||||
group.observeField("musicSongSelected", m.port)
|
||||
|
||||
return group
|
||||
|
@ -398,6 +399,43 @@ function CreateVideoPlayerGroup(video_id, mediaSourceId = invalid, audio_stream_
|
|||
return video
|
||||
end function
|
||||
|
||||
sub controlaudioplay()
|
||||
if (m.audio.state = "finished")
|
||||
m.audio.control = "stop"
|
||||
m.audio.control = "none"
|
||||
end if
|
||||
end sub
|
||||
|
||||
' Play Audio
|
||||
function CreateAudioPlayerGroup(audio)
|
||||
print "[INFO] Playing ", audio.title
|
||||
|
||||
songData = AudioItem(audio.id)
|
||||
|
||||
m.audio = createObject("RoSGNode", "Audio")
|
||||
m.audio.observeField("state", "controlaudioplay")
|
||||
m.audio.content = createObject("RoSGNode", "ContentNode")
|
||||
|
||||
params = {}
|
||||
|
||||
params.append({
|
||||
"Static": "true",
|
||||
"Container": songData.mediaSources[0].container,
|
||||
})
|
||||
|
||||
params.MediaSourceId = songData.mediaSources[0].id
|
||||
|
||||
m.audio.content.url = buildURL(Substitute("Audio/{0}/stream", audio.id), params)
|
||||
m.audio.content.title = audio.title
|
||||
m.audio.content.streamformat = songData.mediaSources[0].container
|
||||
|
||||
m.audio.control = "stop"
|
||||
m.audio.control = "none"
|
||||
m.audio.control = "play"
|
||||
|
||||
return ""
|
||||
end function
|
||||
|
||||
function CreatePersonView(personData as object) as object
|
||||
person = CreateObject("roSGNode", "PersonDetails")
|
||||
m.global.SceneManager.callFunc("pushScene", person)
|
||||
|
|
|
@ -131,8 +131,11 @@ function ItemMetaData(id as string)
|
|||
tmp.json = data
|
||||
return tmp
|
||||
else if data.type = "Audio"
|
||||
print "Items.brs::ItemMetaData for Audio not yet supported"
|
||||
return data
|
||||
' User clicked on a song and wants it to play
|
||||
tmp = CreateObject("roSGNode", "MusicSongData")
|
||||
tmp.image = PosterImage(data.id)
|
||||
tmp.json = data
|
||||
return tmp
|
||||
else
|
||||
print "Items.brs::ItemMetaData processed unhandled type: " data.type
|
||||
' Return json if we don't know what it is
|
||||
|
@ -184,6 +187,27 @@ function MusicSongList(id as string)
|
|||
return data
|
||||
end function
|
||||
|
||||
' Get Songs that are on an Album
|
||||
function AudioItem(id as string)
|
||||
url = Substitute("Users/{0}/Items/{1}", get_setting("active_user"), id)
|
||||
resp = APIRequest(url, {
|
||||
"UserId": get_setting("active_user"),
|
||||
"includeitemtypes": "Audio"
|
||||
"sortBy": "SortName"
|
||||
})
|
||||
|
||||
data = getJson(resp)
|
||||
results = []
|
||||
for each item in data.Items
|
||||
tmp = CreateObject("roSGNode", "MusicSongData")
|
||||
tmp.image = PosterImage(item.id)
|
||||
tmp.json = item
|
||||
results.push(tmp)
|
||||
end for
|
||||
data.Items = results
|
||||
return data
|
||||
end function
|
||||
|
||||
' Seasons for a TV Show
|
||||
function TVSeasons(id as string)
|
||||
url = Substitute("Shows/{0}/Seasons", id)
|
||||
|
|
Loading…
Reference in New Issue
Block a user