I want to download bass dll manually and then play mp3 file. How to do it? Delphi XE2.
My attempt does not work:
type
QWORD = Int64;
HSTREAM = LongWord;
type
TBASS_ChannelPlay = function(handle: HSTREAM; restart: LongBool): LongBool; stdcall;
type
TBASS_StreamCreateFile = function(mem: LongBool; f: Pointer;
offset, length: QWORD; flags: LongWord): HSTREAM; stdcall;
procedure PlayMP3(FileName: string);
var
BASS_ChannelPlay: TBASS_ChannelPlay;
BASS_StreamCreateFile: TBASS_StreamCreateFile;
DllHandle: THandle;
MP3Stream: HSTREAM;
DllPath:string;
pFileName:pchar;
begin
DllPath:= 'c:\dll\bass.dll';
DllHandle := LoadLibrary(pchar(DLLPath));
try
if DllHandle = 0 then
Exit;
@BASS_StreamCreateFile := GetProcAddress(DllHandle,
'BASS_StreamCreateFile');
if @BASS_StreamCreateFile <> nil then
begin
pfilename:=pchar(FileName);
MP3Stream := BASS_StreamCreateFile(false, Pfilename, 0, 0, 0);
if MP3Stream <> 0 then
begin
@BASS_ChannelPlay := GetProcAddress(DllHandle, 'BASS_ChannelPlay');
if @BASS_ChannelPlay <> nil then
BASS_ChannelPlay(MP3Stream,false);
end;
end;
finally
FreeLibrary(DllHandle);
end;
end;
But BASS_StreamCreateFile returns 0 all the time: (
Code from their example (Bass Test) and Bass.pas:
type
DWORD = LongWord;
BOOL = LongBool;
QWORD = Int64;
HSTREAM = DWORD;
function BASS_StreamCreateFile(mem: BOOL; f: Pointer; offset, length: QWORD; flags: DWORD): HSTREAM; {$IFDEF WIN32}stdcall{$ELSE}cdecl{$ENDIF}; external bassdll;
strs: array[0..128] of HSTREAM;
procedure TForm1.Button15Click(Sender: TObject);
var
f: PChar;
begin
if not OpenDialog2.Execute then Exit;
f := PChar(OpenDialog2.FileName);
strs[strc] := BASS_StreamCreateFile(False, f, 0, 0, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
if strs[strc] <> 0 then
begin
ListBox3.Items.Add(OpenDialog2.FileName);
Inc(strc);
end
else
Error('Error creating stream!');
end;
Added
MP3Stream := BASS_StreamCreateFile(false, Pfilename, 0, 0, 0);
ShowMessage(SysErrorMessage(GetLastError));
GetLastError does not detect errors!
Added
There is also BASS 2.4 Delphi (dynamic).
It is written:
How to set Copy DYNAMIC_BASS.PAS to the \ LIB subdirectory of your Delphi path or your dir Call_load_BASSDLL project (e.g. in FormCreate) to load BASS before using any functions and
Unload_BASSDLL (e.g. in FormDestory) to upload it when you are done.
NOTE. Delphi 2009 users should use the BASS_UNICODE flag where possible
I do:
if Load_BASSDLL(DllPath) then
begin
FileName:='C:\Users\V\Desktop\cmd.mp3';
MP3Stream:=BASS_StreamCreateFile(False, pchar(FileName), 0, 0, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
if MP3Stream <> 0 then
BASS_ChannelPlay(MP3Stream, False);
Unload_BASSDLL;
end;
It still doesn't work :(
Added:
BASS_Init(-1, 44100, 0, Form1.Handle, nil);
BASS_ChannelPlay(MP3Stream, False) true, : (