type
TNetRadioThread =
class(TThread)
private
Procedure PlayURL;
public
protected
procedure Execute;
override;
// Net Radio
end;
type
TAudioEngine =
class(TObject)
private
fNetThread :
array of TNetRadioThread;
Destructor TAudioEngine.Destroy;
var i : integer;
begin
{Thread Terminate}
if length(fNetThread) > 0
then
begin
for i := 0
to length(fNetThread) - 1
do
fNetThread[i].Terminate;
end;
{Free Bass}
BASS_Free;
end;
{---------------------------- NetRadio Thread ---------------------------------}
procedure DownloadProc(buffer: Pointer; length: DWORD; user: DWORD);
stdcall;
begin
with AudioPlayer
do // Get Server Status
begin
if (buffer <>
nil)
and (length = 0)
then
fServerStatus:= PChar(buffer)
end;
end;
procedure TNetRadioThread.Execute;
var i : integer;
begin
try
PlayURL;
// test
except
on E:
Exception do
ShowMessage(E.
Message);
end;
end;
procedure TNetRadioThread.PlayURL;
var Flag : DWORD;
i : integer;
begin
With AudioPlayer
do
begin
BASS_StreamFree(Channel);
BASS_MusicFree(Channel);
PlayerState:= ENGINE_PLAYER_CONNECTING;
Flag:= BASS_STREAM_STATUS;
Channel:= BASS_StreamCreateURL(PChar(FFilename), 0, Flag, @DownloadProc, 0);
if Channel = 0
then
Channel:= BASS_FLAC_StreamCreateURL(PChar(FFileName), 0, Flag, @DownloadProc, 0);
if Channel = 0
then
Channel:= BASS_AAC_StreamCreateURL(PChar(FFileName), 0, Flag, @DownloadProc, 0);
if Channel = 0
then
Channel:= BASS_AC3_StreamCreateURL(PChar(FFileName), 0, Flag, @DownloadProc, 0);
if Channel = 0
then
Channel:= BASS_SPX_StreamCreateURL(PChar(FFileName), 0, Flag, @DownloadProc, 0);
//Synchronize('');
if BASS_ChannelPlay(Channel, true)
then
PlayerState:= ENGINE_PLAYER_PLAY
else
PlayerState:= ENGINE_PLAYER_STOP
end;
end;
{---------------------------------- Play URL ----------------------------------}
Procedure TAudioEngine.PlayURL;
var i : integer;
begin
if length(fNetThread) > 0
then
begin
for i := 0
to length(fNetThread) - 1
do
begin
fNetThread[i].Terminate;
end;
end;
Setlength(fNetThread, 1);
// test
for i := 0
to length(fNetThread) - 1
do
begin
fNetThread[i]:= TNetRadioThread.Create(true);
fNetThread[i].Priority := tpNormal;
fNetThread[i].FreeOnTerminate := True;
fNetThread[i].Resume;
end;
end;
{--------------------------------- Load File ---------------------------------}
Procedure TAudioEngine.PlayFile(Filename :
String);
var Flag : DWORD;
begin
FFilename:= Filename;
if isURL(Filename)
then
begin
PlayURL;
exit;
end;
Procedure TAudioEngine.Stop();
var i : integer;
begin
if length(fNetThread) > 0
then
begin
for i := 0
to length(fNetThread) - 1
do
fNetThread[i].Terminate;
end;
if BASS_ChannelStop(Channel)
then
PlayerState:= ENGINE_PLAYER_STOP;
end;