Stream Buffering Message

Started by ChrisM,

ChrisM

Hi All,

I am using the BASS dll in my VB application to play a net radio stream. Every so often (as occurs with stremaing audio), the streams stops for a couple of seconds to re-buffer (net traffic etc.). Is there anyway to catch this procedure and display a message in the application to inform the user that the stream is currently buffering?

At the moment, if the stream goes dead for a while to re-buffer, the user has no way of knowing what the progrma is doing. Can the BASS Dll raise an error event when the stream is rebuffered, so I can display a "Buffering..." message in the application?

Thanks in advance for any advice :)

Regards,
Chris

Azoth

Chris,
  The BASS_ChannelIsActive() will return the flag BASS_ACTIVE_STALLED when the playback of the stream has been stalled due to there not being enough data downloaded to continue playing. The playback will automatically resume once sufficient data has been downloaded to do so. The return value will change to BASS_ACTIVE_PLAYING once the stream begins playing again.

Take a look at the BASS_ChannelIsActive() function to determine wheather the stream has stalled and the BASS_StreamGetFilePosition() function to see an example of how to get the percentage downloaded of an internet file stream.

.Azoth.

ChrisM

Hi Azoth,

Thanks for your help here :)

Does this mean I need to have a timer running continuously to keep checking the stream state? As the re-buffer times  are very quick it would mean the timer would have to be running at very fast rate. This would use up a lot of CPU time, surely?

Is there not a way that the BASS DLL can raise an error when the stream has stalled, or have a function with something like "OnStatusChanged" so it's more of an "event" procedure as opposed to a "check for"?

Any ideas welcome,

Many Thanks,
Chris

Ian @ un4seen

You're probably already using a timer for the time/position display updating. That's the ideal place to check if the stream has stalled, as you'll probably want to display "stalled" or "buffering" right there :)

ChrisM

No, I currently don't use a timer, which is why I asked.

The app just displays "Playing..." when the stream is going, and the message doesn't change when it stalls.

As the stream is a live radio show, there is no need for a counter and current position timer.

Best Regards,
Chris

Azoth

Chris,
  Since there isn't a Synchronizer that can be set using BASS_ChannelSetSync() your only option is to setup a timer and perform a check for the BASS_ACTIVE_STALLED flag. A timer set to 500ms, 1/2 second, would have a negliable performance hit, even on a lower end system. This is primarily because VB timers have a very low priority, so if the system is really busy with other programs, it will take a few extra ms before the event actually fires.

   Beleive me, I'm not a big fan of timers either, especially for high accuracy uses. But for playback display and simple flag checking, it's the most practical and easiest solution.

.Azoth.

ChrisM

Hi Azoth,

Thanks for your suggestions, I will give it a go :)

I try to refrain from using the VB timers and only use the system timers (via Windows API) - these are more accurate.

If I were to use system timers instead, would that have any noticable effect at 500ms?

Regards,
Chris

Azoth

Chris,
    I use the High-Performance Timer Objects/VB6 part of the CCRP. Having several timers set to a Interval of 1ms and a Frequency of 1ms I saw no additional CPU usage on a AthlonXP 1400+/512/XP. On one of my test boxes (Athlon 550Mhz, 256 & Win98) with the same settings it added 2% to the CPU load. So I would say that one timer @ 500ms would not cause any burden to the system.

http://www.mvps.org/ccrp/

.Azoth.

ChrisM

Hi Azoth,

Thanks for all your suggestions, I certainly have something to work with! Also, thanks for the URL, very useful indeed!

Regards,
Chris