BASS_ChannelGetLength

Retrieves the length of a channel.

QWORD BASS_ChannelGetLength(
    DWORD handle,
    DWORD mode
);

Parameters

handleThe channel handle... a HCHANNEL, HMUSIC, HSTREAM. HSAMPLE handles may also be used.
modeHow to retrieve the length. One of the following.
BASS_POS_BYTEGet the length in bytes.
BASS_POS_MUSIC_ORDERGet the length in orders. (HMUSIC only)
BASS_POS_OGGGet the number of bitstreams in an OGG file.
other modes may be supported by add-ons, see the documentation.

Return value

If successful, then the channel's length is returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTAVAILThe requested length is not available.

Remarks

The exact length of a stream will be returned once the whole file has been streamed, but until then it is not always possible to 100% accurately estimate the length. The length is always exact for MP3/MP2/MP1 files when the BASS_STREAM_PRESCAN flag is used in the BASS_StreamCreateFile call, otherwise it is an (usually accurate) estimation based on the file size. The length returned for OGG files will usually be exact (assuming the file is not corrupt), but when streaming from the internet (or "buffered" user file), it can be a very rough estimation until the whole file has been downloaded.

Retrieving the byte length of a MOD music requires that the BASS_MUSIC_PRESCAN flag was used in the BASS_MusicLoad call.

Example

Get the duration (in seconds) of a channel.
QWORD len = BASS_ChannelGetLength(channel, BASS_POS_BYTE); // the length in bytes
double time = BASS_ChannelBytes2Seconds(channel, len); // the length in seconds

See also

BASS_ChannelBytes2Seconds, BASS_ChannelGetPosition, BASS_ChannelSetPosition, BASS_StreamGetFilePosition