unit UBassPlayer;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, bass;
type
TPlayer =
class
private
strs: HSTREAM;
FPause:Boolean;
FPlay:Boolean;
FStop:Boolean;
public
constructor CreatePlayer();
Procedure FreePlayer;
Procedure LoadFile(Filename:
String);
Procedure Play();
Procedure Stop();
Procedure Pause();
end;
implementation
Procedure TPlayer.Pause;
begin
BASS_ChannelStop(STRS);
FStop:=false;
FPause:=true;
FPlay:=false;
end;
Procedure TPlayer.Stop;
begin
BASS_ChannelStop(STRS);
FStop:=true;
FPause:=False;
FPlay:=false;
end;
Procedure TPlayer.LoadFile(Filename:
String);
var f:PChar;
begin
BASS_StreamFree(strs);
f:=Pchar(Filename);
if trim(f)='
'
then exit;
strs:= BASS_StreamCreateFile(False, f, 0, 0, BASS_MUSIC_RAMP
OR BASS_UNICODE);
end;
Procedure TPlayer.Play();
begin
if (FStop=false)
and(Fpause=false)
then begin
BASS_ChannelPlay(strs, true);
FPlay:=true;
exit;
end;
if FPause=true
then begin
BASS_ChannelPlay(strs, False);
FPause:=false;
FPlay:=true;
exit;
end;
if FStop=true
then begin
BASS_ChannelPlay(strs, true);
FStop:=false;
FPlay:=true;
exit;
end;
end;
constructor TPlayer.CreatePlayer();
begin
inherited Create;
if (HIWORD(BASS_GetVersion) <> BASSVERSION)
then
begin
MessageBox(0,'
An incorrect version of BASS.DLL was loaded',
nil,MB_ICONERROR);
Halt;
end;
// Initialize audio - default device, 44100hz, stereo, 16 bits
if not BASS_Init(-1, 44100, 0, Application.Handle,
nil)
then
showmessage('
Error initializing audio!');
FPause:=False;
FPlay:=false;
FStop:=false;
end;
Procedure TPlayer.FreePlayer;
begin
BASS_StreamFree(strs);
BASS_Free();
end;
end.