Play song when selected

This commit is contained in:
1hitsong 2022-05-14 22:30:29 -04:00
parent 183ada1f5c
commit 158b7623ba
3 changed files with 70 additions and 6 deletions

View File

@ -158,6 +158,8 @@ sub Main (args as dynamic) as void
group = CreateMusicArtistDetailsGroup(selectedItem.json) group = CreateMusicArtistDetailsGroup(selectedItem.json)
else if selectedItem.type = "MusicAlbum" else if selectedItem.type = "MusicAlbum"
group = CreateMusicAlbumDetailsGroup(selectedItem.json) group = CreateMusicAlbumDetailsGroup(selectedItem.json)
else if selectedItem.type = "Audio"
group = CreateAudioPlayerGroup(selectedItem.json)
else else
' TODO - switch on more node types ' TODO - switch on more node types
message_dialog("This type is not yet supported: " + selectedItem.type + ".") 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]] node = albums.musicArtistAlbumData.items[ptr[1]]
group = CreateMusicAlbumDetailsGroup(node) group = CreateMusicAlbumDetailsGroup(node)
else if isNodeEvent(msg, "musicSongSelected") else if isNodeEvent(msg, "musicSongSelected")
' If you select a Song from ANYWHERE, follow this flow
' Enjoy the silence selectedIndex = msg.getData()
message_dialog("Playing songs is not yet supported.") songs = msg.getRoSGNode()
group = CreateAudioPlayerGroup(songs.MusicArtistAlbumData.items[selectedIndex])
else if isNodeEvent(msg, "episodeSelected") else if isNodeEvent(msg, "episodeSelected")
' If you select a TV Episode from ANYWHERE, follow this flow ' If you select a TV Episode from ANYWHERE, follow this flow
node = getMsgPicker(msg, "picker") node = getMsgPicker(msg, "picker")

View File

@ -342,6 +342,7 @@ function CreateMusicAlbumDetailsGroup(album)
group.itemContent = ItemMetaData(album.id) group.itemContent = ItemMetaData(album.id)
group.musicArtistAlbumData = MusicSongList(album.id) group.musicArtistAlbumData = MusicSongList(album.id)
' Watch for user clicking on a song
group.observeField("musicSongSelected", m.port) group.observeField("musicSongSelected", m.port)
return group return group
@ -398,6 +399,43 @@ function CreateVideoPlayerGroup(video_id, mediaSourceId = invalid, audio_stream_
return video return video
end function 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 function CreatePersonView(personData as object) as object
person = CreateObject("roSGNode", "PersonDetails") person = CreateObject("roSGNode", "PersonDetails")
m.global.SceneManager.callFunc("pushScene", person) m.global.SceneManager.callFunc("pushScene", person)

View File

@ -131,8 +131,11 @@ function ItemMetaData(id as string)
tmp.json = data tmp.json = data
return tmp return tmp
else if data.type = "Audio" else if data.type = "Audio"
print "Items.brs::ItemMetaData for Audio not yet supported" ' User clicked on a song and wants it to play
return data tmp = CreateObject("roSGNode", "MusicSongData")
tmp.image = PosterImage(data.id)
tmp.json = data
return tmp
else else
print "Items.brs::ItemMetaData processed unhandled type: " data.type print "Items.brs::ItemMetaData processed unhandled type: " data.type
' Return json if we don't know what it is ' Return json if we don't know what it is
@ -184,6 +187,27 @@ function MusicSongList(id as string)
return data return data
end function 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 ' Seasons for a TV Show
function TVSeasons(id as string) function TVSeasons(id as string)
url = Substitute("Shows/{0}/Seasons", id) url = Substitute("Shows/{0}/Seasons", id)