Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
rsromeo
Level 7

WAITING FOR AN EVENT

Hi -

Was wondering if someone could clue me in on how to do something. I have an audio player object loading an mp3 file. While the player is loading the file, it gives the "startup progress" message and I display one line dialog saying "buffering, etc."

But if the link is bad, it never quits the loop. It doesn't give any other messages, just sticks on "startup progress" so how can I tell it to time out after XXXX seconds and display a message dialog "cannot connect, etc." ?
0 Kudos
2 REPLIES 2\
RokuChris
Roku Employee
Roku Employee

Re: WAITING FOR AN EVENT

This is a common problem. One way to detect a stalled buffer is if you don't receive any events from your audio player for some period of time before receiving the "start of play" message. Here's a simple event loop that does that. This is from memory, so it may not work exactly as is, but the concept is there.

audioPlayer.Play()
isBuffering = true

while true
msg = wait(5000, audioPlayer.GetMessagePort())
if msg <> invalid
' we have a valid message
if msg.isStatusMessage()
if msg.GetMessage() = "start of play"
' buffering was successful
isBuffering = false
end if
end if
else
' no message received in 5 seconds
if isbuffering
' handle a stalled buffering situation
end if
end if
end while
0 Kudos
rsromeo
Level 7

Re: WAITING FOR AN EVENT

Thanks RokuChris. I'll give it a try.
0 Kudos