AUDIO PLAYLIST HELP

Hi all..have a question regarding playing audio (mp3) content back to back.
I first create a blank image canvas (going to use it for something else later) and want to play an array of audio content over it.
The audio plays fine and loads each track in the array. The problem is I can’t get out of it. I’m stuck in the inner while loop (for the audio) and when I have a “image canvas” event like pressing up remote key to exit, it doesn’t respond until the playlist is finished. Any help would be appreciated. Been a while since I’ve coded with BS.

Function showPlaylistImageCanvas(category As Object, showList As Object, showIndex as Integer) as void

canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
canvas.Show()

    'start with second item in list - first item is only a placeholder
    showIndex = getNextShow(showList, showIndex)
    show = showList[showIndex]
    audio2 = CreateObject("roAudioPlayer")
    port2 = CreateObject("roMessagePort")
    audio2.SetMessagePort(port2)
    item = CreateObject("roAssociativeArray")
    item.isPlayState = 0
    item.Url = show.StreamUrls[0]
    item.StreamFormat = "mp3"
    audio2.AddContent(item)
    audio2.SetLoop(false)
    audio2.Play()

while true

msg2 = wait(0, port2)
if type(msg2) = "roAudioPlayerEvent"

if msg2.isStatusMessage() then
print "roAudioPlayerEvent: "; msg2.getmessage()

if msg2.getmessage() = "end of stream" then
print "end of stream"
showIndex = getNextShow(showList, showIndex)
show = showList[showIndex]
item = CreateObject("roAssociativeArray")
item.isPlayState = 0
item.Url = show.StreamUrls[0]
item.StreamFormat = "mp3"
audio2.AddContent(item)
audio2.SetLoop(false)
audio2.Play()

elseif msg2.getmessage() = "end of playlist" then
audio2.Stop()
shouldPlaylistExit = true
endif

endif
endif

 if shouldPlaylistExit
    exit while
  end if

end while

'while loop for image canvas
while(true)
msg = wait(0,port)
if type(msg) = "roImageCanvasEvent" then
if (msg.isRemoteKeyPressed()) then
i = msg.GetIndex()
print "Key Pressed - " ; msg.GetIndex()
if (i = 2) then
' Up - Close the screen.
canvas.close()
end if
else if (msg.isScreenClosed()) then
print "Closed"
return
end if
end if
end while

End function

Your audio player and image canvas need to share the same message port, so you can have a single message loop that listens to both.

Thanks TheEndless. I revised the code and am now sharing image canvas and audioplayer on same port but now the audio tracks don’t advance. It plays one and playlist ends.

canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
'Set opaque background
canvas.SetLayer(0, {Color:"#FF000000", CompositionMode:"Source"})
canvas.Show()

shouldPlaylistExit = false
showIndex = getNextShow(showList, showIndex)
show = showList[showIndex]
audio2 = CreateObject("roAudioPlayer")
audio2.SetMessagePort(port)
item = CreateObject("roAssociativeArray")
item.isPlayState = 0
item.Url = show.StreamUrls[0]
item.StreamFormat = "mp3"
audio2.AddContent(item)
audio2.SetLoop(false)
audio2.Play()

while true

msg = wait(0, port)
if type(msg) = "roAudioPlayerEvent" then

if msg.isStatusMessage() then
print "roAudioPlayerEvent: "; msg.getmessage()

if msg.getmessage() = "end of stream" then
print "end of stream"
showIndex = getNextShow(showList, showIndex)
show = showList[showIndex]
audio2 = CreateObject("roAudioPlayer")
item = CreateObject("roAssociativeArray")
item.isPlayState = 0
item.Url = show.StreamUrls[0]
item.StreamFormat = "mp3"
audio2.AddContent(item)
audio2.SetLoop(false)
audio2.Play()
elseif msg.getmessage() = "end of playlist" then
audio2.Stop()
shouldPlaylistExit = true
endif

endif

elseif type(msg) = "roImageCanvasEvent" then
if (msg.isRemoteKeyPressed()) then
i = msg.GetIndex()
print "Key Pressed - " ; msg.GetIndex()
if (i = 2) then
canvas.close()
end if
elseif (msg.isScreenClosed()) then
print "Closed"
return
end if
end if

 if shouldPlaylistExit
exit while
  end if

end while

It looks like you are adding content one song at a time - try adding all the content items before the wait loop starts.

Thanks for your help guys! I have it working now!! :slightly_smiling_face: