procedure StatusProc(buffer: Pointer; len, user: DWORD);
stdcall;
begin
if (buffer <>
nil)
and (len = 0)
then
SendMessage(win, WM_INFO_UPDATE, 8, DWORD(PChar(buffer)));
end;
function OpenURL(
url: PChar): Integer;
var
icy: PChar;
Len, Progress: DWORD;
begin
Result := 0;
BASS_StreamFree(chan);
// close old stream
progress := 0;
SendMessage(win, WM_INFO_UPDATE, 0, 0);
// reset the Labels and trying connecting
chan := BASS_StreamCreateURL(
url, 0, BASS_STREAM_STATUS, @StatusProc, 0);
if (chan = 0)
then
begin
//lets catch the error here inside the Thread
// and send it to the WndProc
SendMessage(win, WM_INFO_UPDATE, 1, Bass_ErrorGetCode());
// Oops Error
end
else
begin
// Progress
{
du kannst auch den channel Type überprüfen (BASS_ChannelGetInfo BASS_CTYPE_STREAM_WMA )
}
// WMA Prebuffer
if (BASS_StreamGetFilePosition(chan , BASS_FILEPOS_WMA_BUFFER) <> -1)
then
repeat
progress := BASS_StreamGetFilePosition(chan , BASS_FILEPOS_WMA_BUFFER);
if (progress = DW_ERROR)
or (progress = 100)
then
Break;
SendMessage(win, WM_INFO_UPDATE, 2, progress);
// show the Progess value in the label
until
progress >75
else
repeat
len := BASS_StreamGetFilePosition(chan, BASS_FILEPOS_END);
if (len = DW_Error)
then
break;
// something's gone wrong! (eg. BASS_Free called)
progress := (BASS_StreamGetFilePosition(chan, BASS_FILEPOS_DOWNLOAD) -
BASS_StreamGetFilePosition(chan, BASS_FILEPOS_CURRENT)) * 100
div len;
// percentage of buffer filled
SendMessage(win, WM_INFO_UPDATE, 2, progress);
// show the Progess value in the label
until
progress > 75;
// get the broadcast name and bitrate
icy := BASS_ChannelGetTags(chan, BASS_TAG_ICY);
if (icy =
nil)
then
icy := BASS_ChannelGetTags(chan, BASS_TAG_HTTP);
// no ICY tags, try HTTP
if (icy <>
nil)
then
while (icy^ <> #0)
do
begin
if (Copy(icy, 1, 9) = '
icy-name:')
then
SendMessage(win, WM_INFO_UPDATE, 3, DWORD(PChar(Copy(icy, 10, MaxInt))))
else if (Copy(icy, 1, 7) = '
icy-br:')
then
SendMessage(win, WM_INFO_UPDATE, 4, DWORD(PChar('
bitrate: ' + Copy(icy, 8, MaxInt))));
icy := icy + Length(icy) + 1;
end;
// get the stream title and set sync for subsequent titles
DoMeta();
BASS_ChannelSetSync(chan, BASS_SYNC_META, 0, @MetaSync, 0);
// play it!
BASS_ChannelPlay(chan, FALSE);
end;
cthread := 0;
end;