Delphi: load BASS DLL and play MP3

天涯浪子 提交于 2019-12-05 06:38:01

You're missing the call to BASS_Init. From the same demo you quoted from, in the FormCreate event:

// Initialize audio - default device, 44100hz, stereo, 16 bits
if not BASS_Init(-1, 44100, 0, Handle, nil) then
  Error('Error initializing audio!'); 

Also, look at the demo source's call:

BASS_StreamCreateFile(False, f, 0, 0, 
 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});

Note what happens with the last parameter? The or BASS_UNICODE is required on D2009 and up, unless you're using PAnsiChar instead of PChar; Delphi's default string type is UnicodeString, and the default PChar is PWideChar.

You can use it with the {$IFDEF UNICODE} or without it; Delphi defines UNICODE, so if you use it your code will be backwards-compatible with earlier versions of Delphi (pre-D2009) as well.

You should also look at dynamic_bass.pas in the Bass\Delphi\dynamic folder. It has code to dynamically load the library and retrieve all the functions; if you don't want to use it directly, at least you could copy the function definitions and dynamic loading code you need from there instead.

Suggestion - just don't load the .dll manually. Forget "LoadDll" and ESPECIALLY forget all that grungy, low-level Win3.0 era "GetProcAddress()" nonsense.

Just declare an external, just like the working Bass sample code successfully does:

function BASS_StreamCreateFile(
           mem: BOOL; 
           f: Pointer; 
           offset, length: QWORD; 
           flags: DWORD): HSTREAM; 
{$IFDEF WIN32}stdcall{$ELSE}cdecl{$ENDIF}; external bassdll;

PS: If you really, really, REALLY insist on LoadDll () and friends, then:

  1. Remember that Delphi XE strings are now 16-bit Unicode

  2. Check GetLastError () to determine exactly WHY LoadDll returned a null handle.

PPS:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!