Forum Discussion

rsromeo's avatar
rsromeo
Channel Surfer
15 years ago

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." ?

2 Replies

  • 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