BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_ChannelGetLength Method (Int32)BASS.NET API for the Un4seen BASS Audio Library
Retrieves the playback length in bytes of a channel.

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

public static long BASS_ChannelGetLength(
	int handle
)

Parameters

handle
Type: SystemInt32
The channel handle... a HCHANNEL, HMUSIC, HSTREAM. HSAMPLE handles may also be used.

Return Value

Type: Int64
If succesful, then the channel's length is returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.
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(String, Int64, Int64, BASSFlag) 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. It will also be an estimate for chained OGG files that are not pre-scanned.

Unless an OGG file contains a single bitstream, the number of bitstreams it contains will only be available if it was pre-scanned at the stream's creation.

Retrieving the length of a MOD music requires that the BASS_MUSIC_PRESCAN flag was used in the BASS_MusicLoad(String, Int64, Int32, BASSFlag, Int32) call.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not a valid channel.
BASS_ERROR_NOTAVAILThe length is not available.

Examples

Get the duration (in seconds) of a channel:
VB
' length in bytes
Dim len As Long = Bass.BASS_ChannelGetLength(channel)
' the time length
Dim time As Double = Bass.BASS_ChannelBytes2Seconds(channel, len)
// length in bytes
long len = Bass.BASS_ChannelGetLength(channel);
// the time length
double time = Bass.BASS_ChannelBytes2Seconds(channel, len);
See Also

Reference