Author Topic: BASS HLS for Android: Sync for when a segment starts playing?  (Read 112 times)


  • Posts: 3

I'm trying to configure BASS in my android app to play HLS streams. I'm trying to figure out a way to run some code when a particular segment begins playing, although I can't seem to find a callback/sync to do so. I tried to somehow use BASS_SYNC_HLS_SEGMENT but it triggers when a segment starts downloading and not playing, which creates offset issues.

I'm quite new to BASS, so its entirely possible I have missed some configuration detail and would greatly appreciate any help here!
« Last Edit: 27 Feb '18 - 11:20 by hunar15 »

Ian @ un4seen

  • Administrator
  • Posts: 20667
Unfortunately, it isn't really possible to know exactly when a segment begins playing; BASSHLS feeds the data to the decoder's buffer without knowing when it will be decoded and then played. But you could try using the amount of buffered data to estimate when a segment will begin playing, something like this:

Code: [Select]
int decoded = BASS.BASS_ChannelGetData(handle, NULL, BASS.BASS_DATA_AVAILABLE); // get buffered decoded data
long encoded = BASS.BASS_StreamGetFilePosition(handle, BASS.BASS_FILEPOS_BUFFER); // get buffered encoded data
Float bitrate = 0.f;
BASS.BASS_ChannelGetAttribute(handle, BASS.BASS_ATTRIB_BITRATE, bitrate); // get the bitrate
double delay = BASS.BASS_ChannelBytes2Seconds(handle, decoder) // delay from decoded data
+ (double)encoded / (bitrate * 125); // + delay from encoded data

Do you want to know when the segment begins for title updates? If so, as the segments are usually all the same length, the timing of the titles isn't going to be precise anyway, ie. it probahly woudn't appear to be in sync even if you did know exactly when the segment begins playing.


  • Posts: 3
Hey Ian,

Yes, this is for title updates. I agree that it won't be very accurate but your code has helped in making it much better. Thanks a ton for your help!