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(alias:
string): Integer;
procedure play(alias:
string);
procedure pausePlay(alias:
string);
procedure stop(alias:
string);
constructor Create(fileName:
string; dtype:
string; alias:
string; autoplay: Bool);
destructor Destroy(alias:
string);
override;
{<<<<<<<<<<<}
end;
implementation
constructor TMCIPlayer.Create(fileName:
string; dtype:
string; alias:
string; autoplay: Bool);
var
lResult: cardinal;
begin
//Variablen initiieren
paused := FALSE;
resultSize := 255;
// We want to play a File.
command := PWideChar('
open "' + fileName + '
" type ' + dtype + '
alias ' + alias + '
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(alias:
string);
begin
command := ('
close '+ alias +'
wait');
mciSendString(command, return, resultSize, 0);
end;
function TMCIPlayer.getPosition(alias:
string): Integer;
begin
command := ('
status '+ alias +'
position wait');
mciSendString(command, return, resultSize, 0);
if (StrLen(return) > 0)
then
result := StrToInt(return)
else
result := 0;
end;
procedure TMCIPlayer.pausePlay(alias:
string);
begin
paused :=
not paused;
if paused
then
begin
command := ('
pause '+ alias +'
notify');
mciSendString(command, return, resultSize, 0);
end else
begin
command := ('
resume '+ alias +'
notify');
mciSendString(command, return, resultSize, 0);
end;
end;
procedure TMCIPlayer.play(alias:
string);
begin
command := ('
play ' + alias + '
notify');
mciSendString(command, return, resultSize, 0);
end;
procedure TMCIPlayer.stop(alias:
string);
begin
command := ('
stop '+ alias +'
notify');
mciSendString(command, return, resultSize, 0);
end;
end.