DOWNLOADPROC callback

Internet stream download callback function.

void CALLBACK DownloadProc(
    const void *buffer,
    DWORD length,
    void *user
);

Parameters

bufferPointer to the downloaded data... NULL = finished downloading.
lengthThe number of bytes in the buffer... 0 = HTTP or ICY tags.
userThe user instance data given when BASS_StreamCreateURL (or an add-on variant) was called.

Remarks

This callback function will begin receiving data before the BASS_StreamCreateURL call returns (if successful), so any initialization (eg. creating the file if writing to disk) needs to be done before that call or within this function.

When the BASS_STREAM_STATUS flag is specified in the BASS_StreamCreateURL call, HTTP and/or ICY tags may be received before any data is, possibly multiple times for playlists or redirects. The tags are exactly as would be returned by BASS_ChannelGetTags. You can distinguish between HTTP and ICY tags by checking whether the first string starts with "HTTP" or "ICY". The request may be cancelled with BASS_StreamCancel, eg. to prevent a redirect or based on some other criteria.

A download callback function can be used together with a BASS_SYNC_META sync set via BASS_ChannelSetSync to save individual tracks from a Shoutcast stream.

Example

Stream an MP3 file, and save a local copy.
FILE *file = NULL;
...
void CALLBACK MyDownloadProc(const void *buffer, DWORD length, void *user)
{
    if (!file) file = fopen("afile.mp3", "wb"); // create the file
    if (!buffer) fclose(file); // finished downloading
    else fwrite(buffer, 1, length, file);
}
...
HSTREAM stream = BASS_StreamCreateURL("http://www.asite.com/afile.mp3", 0, 0, MyDownloadProc, 0);

See also

BASS_StreamCreateURL