var
URL_SaveFile :
String;
URL_FileStream : TFileStream;
procedure DownloadProc(buffer: Pointer; length: DWORD; user: DWORD);
stdcall;
begin
with AudioPlayer
do
begin
if (URL_SaveFile = '
')
then
exit;
if (URL_FileStream =
nil)
then
URL_FileStream:= TFileStream.Create(URL_SaveFile, fmCreate);
// create the file
if (buffer =
nil)
then
URL_FileStream.Free
// finished downloading
else
URL_FileStream.
Write(buffer^, length);
end;
end;
function TAudioEngine.PlayURL(
URL :
String) : boolean;
var SngLen : Integer; Flags : DWORD;
begin
Cur_FileName:=
URL;
BASS_MusicFree(Channel);
BASS_StreamFree(Channel);
URL_FileStream:=
nil;
Flags:= 0;
if StrBlock
then
Flags:= BASS_STREAM_BLOCK;
{ (BASS_STREAM_BLOCK) Download and play the file in smaller chunks.
Uses a lot less memory than otherwise,
but it's not possible to seek or loop the stream - once it's ended,
the file must be opened again to play it again.
This flag will automatically be applied when the file length is unknown,
for example with Shout/Icecast streams.
This flag also has the effect of resticting the download rate.}
Flags:= Flags
or BASS_STREAM_META
or BASS_STREAM_STATUS;
Channel := THandle(BASS_StreamCreateURL(PChar(Cur_FileName), 0, Flags, @DOWNLOADPROC, 0));
SngLen := 0;
if (Channel = 0)
then
Result := False
else
Result := True;
if not BASS_ChannelPlay(Channel, false)
then
Result := False;
if (SngLen = 0)
then
SongLength := BASS_StreamGetLength(Channel);
PlayerState := ENGINE_PLAY;
end;