BASS_StreamGetFilePosition
Retrieves the file position/status of a stream.
QWORD BASS_StreamGetFilePosition( HSTREAM handle, DWORD mode );
Parameters
handle | The stream handle. | ||||||||||||||||
mode | The file position/status to retrieve. One of the following.
|
Return value
If successful, then the requested file position/status is returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.Error codes
BASS_ERROR_HANDLE | handle is not valid. |
BASS_ERROR_NOTFILE | The stream is not a file stream. |
BASS_ERROR_NOTAVAIL | The requested file position/status is not available. |
Remarks
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 BASS_FILEPOS_CURRENT, BASS_FILEPOS_DOWNLOAD, and BASS_FILEPOS_END positions. This is useful for average bitrate calculations, but it means that they may not be actual file positions. The BASS_FILEPOS_START position can be added 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 is unwise to use the BASS_FILEPOS_CURRENT position for syncing purposes because it gives the position that is being decoded, not the position that is being heard. Use BASS_ChannelGetPosition and/or BASS_ChannelSetSync instead.
Example
Get the average bitrate of a file.float time=BASS_ChannelBytes2Seconds(stream, BASS_ChannelGetLength(stream, BASS_POS_BYTE)); // playback duration DWORD len=BASS_StreamGetFilePosition(stream, BASS_FILEPOS_END); // file length DWORD bitrate=(DWORD)(len/(125*time)+0.5); // bitrate (Kbps)
Get the percentage downloaded of an internet file stream, or the buffer level when streaming in blocks.
QWORD len=BASS_StreamGetFilePosition(stream, BASS_FILEPOS_END); // file/buffer length QWORD buf=BASS_StreamGetFilePosition(stream, BASS_FILEPOS_BUFFER); // buffer level float progress=buf*100.0/len; // percentage of buffer filled