unit MCIPlayer;
interface
uses Windows, Messages, mmsystem, StrUtils, SysUtils, Dialogs;
type
TMCIPlayer =
class
private
{ private-Deklarationen }
command: PWideChar;
return:
array [0..255]
of Widechar;
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;
override;
end;
implementation
{ TMCIPlayer }
constructor TMCIPlayer.Create(fileName:
string; autoplay: Bool);
var
lResult: cardinal;
begin
//init variables
paused := FALSE;
resultSize := 255;
// We want to play a File.
command := PWideChar('
open "' + fileName + '
" type waveaudio alias mciplayer wait');
lResult := mciSendString(command, return, resultSize, 0);
if lResult <> 0
then
begin
mciGetErrorString(lResult, return, 255);
ShowMessage('
MCI error:' + return);
duration := 0;
end;
// Calculate duration
command := ('
set mciplayer time format milliseconds wait');
mciSendString(command, return, resultSize, 0);
command := ('
status mciplayer length wait');
mciSendString(command, return, resultSize, 0);
if (StrLen(return) > 0)
then
duration := StrToInt(return)
else
duration := 0;
if autoplay
then
play;
end;
destructor TMCIPlayer.Destroy;
begin
command := ('
close mciplayer wait');
mciSendString(command, return, resultSize, 0);
end;
function TMCIPlayer.getPosition: Integer;
begin
command := ('
status mciplayer position wait');
mciSendString(command, return, resultSize, 0);
if (StrLen(return) > 0)
then
result := StrToInt(return)
else
result := 0;
end;
procedure TMCIPlayer.pausePlay;
begin
paused :=
not paused;
if paused
then
begin
command := ('
pause mciplayer notify');
mciSendString(command, return, resultSize, 0);
end else
begin
command := ('
resume mciplayer notify');
mciSendString(command, return, resultSize, 0);
end;
end;
procedure TMCIPlayer.play;
begin
command := ('
play mciplayer notify');
mciSendString(command, return, resultSize, 0);
end;
procedure TMCIPlayer.stop;
begin
command := ('
stop mciplayer notify');
mciSendString(command, return, resultSize, 0);
end;
end.