BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_StreamGetFilePosition Method BASS.NET API for the Un4seen BASS Audio Library
Retrieves the decoding/download/end position of a file stream.

Namespace: Un4seen.Bass
Assembly: Bass.Net (in Bass.Net.dll) Version:

public static long BASS_StreamGetFilePosition(
	int handle,
	BASSStreamFilePosition mode


Type: SystemInt32
The stream's handle.
Type: Un4seen.BassBASSStreamFilePosition
The file position to retrieve. One of the following (BASSStreamFilePosition):
BASS_FILEPOS_ASYNCBUFThe amount of data in the asynchronous file reading buffer. This requires that the BASS_ASYNCFILE flag was used at the stream's creation.
BASS_FILEPOS_CURRENTPosition that is to be decoded for playback next. This will be a bit ahead of the position actually being heard due to buffering.
BASS_FILEPOS_ENDEnd of the file, in other words the file length. When streaming in blocks, the file length is unknown, so the download buffer length is returned instead.
BASS_FILEPOS_SIZETotal size of the file.
BASS_FILEPOS_STARTStart of stream data in the file.
BASS_FILEPOS_DOWNLOADDownload progress of an internet file stream or "buffered" user file stream.
BASS_FILEPOS_CONNECTEDInternet file stream or "buffered" user file stream is still connected? 0 = no, 1 = yes.
BASS_FILEPOS_BUFFERThe amount of data in the buffer of an internet file stream or "buffered" user file stream. Unless streaming in blocks, this is the same as BASS_FILEPOS_DOWNLOAD.
BASS_FILEPOS_BUFFERINGThe percentage of buffering remaining before playback of an internet file stream or 'buffered' user file stream can resume.
Other modes may be supported by add-ons, see the documentation.

Return Value

Type: Int64
If succesful, then the requested file position is returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.

ID3 tags (both v1 and v2) and WAVE headers, as well as any other rubbish at the start of the file, are excluded from the calculations of this function.

This is useful for average bitrate calculations, but it means that the BASS_FILEPOS_CURRENT position may not be the actual file position - the BASS_FILEPOS_START position can be added to it to get the actual file position.

When streaming a file from the internet or a "buffered" user file stream, the entire file is downloaded even if the audio data ends before that, in case there are tags to be read. This means that the BASS_FILEPOS_DOWNLOAD position may go beyond the BASS_FILEPOS_END position.

It's unwise to use this function (with mode = BASS_FILEPOS_CURRENT) for syncing purposes because it returns the position that's being decoded, not the position that's being heard. Use BASS_ChannelGetPosition(Int32, BASSMode) for syncing instead.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTFILEThe stream is not a file stream.
BASS_ERROR_NOTAVAILThe requested file position/status is not available.


Get the percentage downloaded of an internet file stream, or the buffering progress when streaming in blocks:
Dim progress As Single
' file length
Dim len As Integer = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END)
' download progress
Dim down As Integer = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD)
' get channel info
Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
' streaming in blocks?
  ' decode position
  Dim dec As Integer = BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)
  ' percentage of buffer used
  progress =(down - dec) * 100F / len
  If progress > 100 Then
    progress = 100 ' restrict to 100 (can be higher)
  End If
  ' percentage of file downloaded
  progress = down * 100F / len
End If
float progress;
// file length
int len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END);
// download progress
int down = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD);
// get channel info
BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
// streaming in blocks?
  // decode position
  int dec = BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT);
  // percentage of buffer used
  progress = (down-dec)*100f / len;
  if (progress > 100)
    progress = 100; // restrict to 100 (can be higher)
  // percentage of file downloaded
  progress = down*100f / len;
Get the average bitrate of a file:
' playback duration
Dim time As Double = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream))
' file length
Dim len As Long = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END)
' bitrate (kbps)
Dim bitrate As Integer = CInt(len /(125 * time) + 0.5)
// playback duration
double time = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream));
// file length
long len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END);
// bitrate (kbps)
int bitrate = (int)(len/(125*time)+0.5d);
See Also