BASS_StreamGetLength

Retrieves the playback length (in bytes) of a file stream (WAV/MP3).

DWORD WINAPI BASS_StreamGetLength(
    HSTREAM handle
);

Parameters
handleThe stream's handle.

Return value
If succesful, then the stream's length is returned, else NULL is returned. Use BASS_ErrorGetCode to get the error code.

Error codes
BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTFILEThe stream is not a file stream... it was not created by using BASS_StreamCreateFile.

Remarks
It's not always possible to 100% accurately estimate the length of a stream, so the length returned may be only an approximation when using some WAV codecs. The length is always accurate for MP3s when the BASS_MP3_SETPOS flag is used with BASS_StreamCreateFile. When the BASS_MP3_SETPOS flag is not used, the length is an estimation based on the file size.

Example
To get the duration (in seconds) of a file stream.

DWORD len,freq,flags,time;
len=BASS_StreamGetLength(a_stream); // length in bytes
BASS_ChannelGetAttributes(a_stream,&freq,0,0); // sample rate
flags=BASS_ChannelGetFlags(a_stream); // stereo/mono, 8/16 bit flags
time=len/(freq*(flags&BASS_SAMPLE_MONO?1:2)*(flags&BASS_SAMPLE_8BITS?1:2)); // the time length

See also
BASS_ChannelSetPosition, BASS_StreamGetBlockLength