unit UBassPlayer;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, bass;
type
TPlayStatus = (plOpen, plActive, plPaused, plStopt, plStalled, plEnd);
TPlayer =
class
private
fStatus : TPlayStatus;
strs: HSTREAM;
public
constructor CreatePlayer();
Procedure FreePlayer;
Function LoadFile(Filename :
String) : Boolean;
Function Play() : Boolean;
Function Pause() : Boolean;
Function Resume() : Boolean;
Function Stop() : Boolean;
Property Get_PlaybackStatus : TPlayStatus
read fStatus;
end;
implementation
Function TPlayer.LoadFile(Filename :
String) : Boolean;
begin
BASS_StreamFree(strs);
strs:= BASS_StreamCreateFile(False, PChar(Filename), 0, 0, BASS_STREAM_AUTOFREE);
if strs = 0
then
begin
Result:= false;
Exit;
end;
fStatus:= plOpen;
Result:= true;
end;
Function TPlayer.Play() : Boolean;
begin
Result:= BASS_ChannelPlay(strs, true);
if Result
then
begin
fStatus:= plActive;
end;
end;
Function TPlayer.Pause() : Boolean;
begin
Result:= BASS_ChannelPause(STRS);
if Result
then
begin
fStatus:= plPause;
end;
end;
Function TPlayer.Resume() : Boolean;
begin
Result:= BASS_ChannelPlay(STRS, false);
if Result
then
begin
fStatus:= plActive;
end;
end;
Function TPlayer.Stop() : Boolean;
begin
Result:= BASS_ChannelStop(STRS);
if Result
then
begin
fStatus:= plStopt;
end;
end;
constructor TPlayer.CreatePlayer() : Boolean;
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!');
end;
end.