Thema: Delphi Syntax SendMCICommand

Einzelnen Beitrag anzeigen

Benutzerbild von Dunkelbunt27
Dunkelbunt27

Registriert seit: 10. Aug 2010
232 Beiträge
 
Delphi XE Professional
 
#30

AW: Syntax SendMCICommand

  Alt 25. Jul 2012, 16:19
Zitat:
Dann füge die neue Declaration auch in der Classe ein ups. hast du ja.
Ansonsten ja auch bei Destroy..
Naja, ist sie doch, oder?
EDIT: Hab dein Edit nicht gesehen, sorry

Das ist die MCIPlayer unit...
Delphi-Quellcode:
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.
FG Dunkelbunt
"Wer zuletzt lacht hat den höchsten Ping"
  Mit Zitat antworten Zitat