Internet stream download callback function.
void CALLBACK DownloadProc(
const void *buffer,
DWORD length,
void *user
);
| buffer | Pointer to the downloaded data... NULL = finished downloading. |
| length | The number of bytes in the buffer... 0 = HTTP or ICY tags. |
| user | The user instance data given when BASS_StreamCreateURL (or an add-on variant) was called. |
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.
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);