unit MidiPlayer;
interface
uses Windows, Messages, mmsystem, StrUtils, SysUtils, Dialogs;
type
TKaraGLPlayer =
class
private
{ private-Deklarationen }
MIDI_Device: Uint;
command: PWideChar;
return:
array [0..50]
of char;
resultSize: Integer;
protected
{ protected-Deklarationen }
public
{ public-Deklarationen }
duration: Integer;
paused: Bool;
function getPosition: Integer;
procedure play;
procedure pausePlay;
procedure stop;
constructor Create(fileName:
string; autoplay: Bool);
destructor Destroy;
end;
implementation
{ TKaraGLPlayer }
constructor TKaraGLPlayer.Create(fileName:
string; autoplay: Bool);
var
lResult: cardinal;
begin
//init variables
paused := FALSE;
MIDI_Device := 0;
resultSize := 50;
// We want to play a MIDI.
command := PWideChar('
open "' + fileName + '
" type sequencer alias karagl wait');
lResult := mciSendString(command, return, resultSize, 0);
if lResult <> 0
then
begin
mciGetErrorString(lResult, return, 50);
ShowMessage('
MCI error:' + return);
duration := 0;
end;
// Calculate duration
command := ('
set karagl time format milliseconds wait');
mciSendString(command, return, resultSize, 0);
command := ('
status karagl length wait');
mciSendString(command, return, resultSize, 0);
if (StrLen(return) > 0)
then
duration := StrToInt(return)
else
duration := 0;
if autoplay
then
play;
end;
destructor TKaraGLPlayer.Destroy;
begin
command := ('
close karagl wait');
mciSendString(command, return, resultSize, 0);
MIDI_Device := 0;
end;
function TKaraGLPlayer.getPosition: Integer;
begin
command := ('
status karagl position wait');
mciSendString(command, return, resultSize, 0);
if (StrLen(return) > 0)
then
result := StrToInt(return)
else
result := 0;
end;
procedure TKaraGLPlayer.pausePlay;
begin
paused :=
not paused;
if paused
then
begin
command := ('
pause karagl notify');
mciSendString(command, return, resultSize, 0);
end else
begin
command := ('
resume karagl notify');
mciSendString(command, return, resultSize, 0);
end;
end;
procedure TKaraGLPlayer.play;
begin
command := ('
play karagl notify');
mciSendString(command, return, resultSize, 0);
end;
procedure TKaraGLPlayer.stop;
begin
command := ('
stop karagl notify');
mciSendString(command, return, resultSize, 0);
end;
end.