This tutorial is the continue of “Making a media player in Delphi”(http://www.delphi-zone.com/2010/03/make-a-media-player-in-delphi/).
In thus tutorial will learn how to make a internet radio player. Of course we will use BASS.DLL(www.un4seen.com).
To begin you’ll need of course Delphi 2010 and BASS api.
So…let’s begin.
1) Create a new project
2) In the form create procedure call:
BASS_Init(-1,44100,0,handle,0); //initialize the bass.dll
3) declare a channel
var
chan: HSTREAM;
chan: HSTREAM;
4) Add this function:
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, nil);
if (chan = 0) then
begin
// SendMessage(win, WM_INFO_UPDATE, 1, 0); // Oops Error
end
else
begin
// Progress
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, nil);
// play it!
BASS_ChannelGetInfo(chan,info); //get channel info
BASS_ChannelSetSync(chan, BASS_SYNC_STALL or BASS_SYNC_MIXTIME, 0, @SongStalledProc, nil); //sync the stream
if BASS_ChannelPlay(chan, FALSE)=false then
begin
Shomessage('The stream can't be played');
end;
end;
cthread := 0;
end;
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, nil);
if (chan = 0) then
begin
// SendMessage(win, WM_INFO_UPDATE, 1, 0); // Oops Error
end
else
begin
// Progress
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, nil);
// play it!
BASS_ChannelGetInfo(chan,info); //get channel info
BASS_ChannelSetSync(chan, BASS_SYNC_STALL or BASS_SYNC_MIXTIME, 0, @SongStalledProc, nil); //sync the stream
if BASS_ChannelPlay(chan, FALSE)=false then
begin
Shomessage('The stream can't be played');
end;
end;
cthread := 0;
end;
You are ready now… The only thing you had to do to play internet radio streams is
OpenURL('radio stream address');


bad bad bad.
no good man. this radio not work!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!suck
Hehhe…just works.. What is the problem? Receive any error messages?
chan := BASS_StreamCreateURL(url, 0, BASS_STREAM_STATUS, @StatusProc-This is ERROR, nil);
I think i didn’t put the StatusProc function right? Drop me a email and i will send to you complete project.
can not work with direct link i.e. “http://38.96.148.28:4410″
It loads a specified radio list, from our servers. It was not designed to load any radio station, but you just gave me a good ideea
I’ve been looking for that solution a few days and have not succeeded as well. until my head exploded taste lol. I think you’re the right person to help me.