mplayer: playerinfos

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3201 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
mgaertner
2014-06-19 13:38:16 +00:00
parent e195112d8b
commit 0650a4a5b4

View File

@ -52,6 +52,12 @@ uses
{$endif} {$endif}
; ;
type
TPlayerStatusEvent = procedure(var Msg: String) of Object;
type
TPlayerErrorEvent = procedure(var Msg: String) of Object;
type type
{ TCustomMPlayerControl } { TCustomMPlayerControl }
@ -63,10 +69,14 @@ type
FLoop: integer; FLoop: integer;
FMPlayerPath: string; FMPlayerPath: string;
FPaused: boolean; FPaused: boolean;
FPlayerInfos:boolean;
fPlayerProcess: TProcessUTF8; fPlayerProcess: TProcessUTF8;
fTimer: TTimer; fTimer: TTimer;
FVolume: integer; FVolume: integer;
FCanvas: TCanvas; FCanvas: TCanvas;
FPlayerStatusEvent : TPlayerStatusEvent;
FPlayerErrorEvent : TPlayerErrorEvent;
procedure SetFilename(const AValue: string); procedure SetFilename(const AValue: string);
procedure SetLoop(const AValue: integer); procedure SetLoop(const AValue: integer);
procedure SetMPlayerPath(const AValue: string); procedure SetMPlayerPath(const AValue: string);
@ -93,8 +103,12 @@ type
property MPlayerPath: string read FMPlayerPath write SetMPlayerPath; property MPlayerPath: string read FMPlayerPath write SetMPlayerPath;
property PlayerProcess: TProcessUTF8 read fPlayerProcess; property PlayerProcess: TProcessUTF8 read fPlayerProcess;
property Paused: boolean read FPaused write SetPaused; property Paused: boolean read FPaused write SetPaused;
property PlayerInfos: boolean read FPlayerInfos write FPlayerInfos;
property Loop: integer read FLoop write SetLoop; // -1 no, 0 forever, 1 once, 2 twice, ... property Loop: integer read FLoop write SetLoop; // -1 no, 0 forever, 1 once, 2 twice, ...
property Volume: integer read FVolume write SetVolume; property Volume: integer read FVolume write SetVolume;
published
property OnPlayerStatusEvent: TPlayerStatusEvent read FPlayerStatusEvent write FPlayerStatusEvent;
property OnPlayerErrorEvent: TPlayerErrorEvent read FPlayerErrorEvent write FPlayerErrorEvent;
end; end;
TMPlayerControl = class(TCustomMPlayerControl) TMPlayerControl = class(TCustomMPlayerControl)
@ -138,23 +152,38 @@ end;
{ TCustomMPlayerControl } { TCustomMPlayerControl }
procedure TCustomMPlayerControl.TimerEvent(Sender: TObject); procedure TCustomMPlayerControl.TimerEvent(Sender: TObject);
var var
OutList, ErrList:TStringlist; OutList, ErrList:TStringlist;
x:integer;
msg:string;
begin begin
if Running then begin if Running then begin
if fPlayerProcess.Output.NumBytesAvailable > 0 then begin if (fPlayerProcess <> nil) and (fPlayerProcess.Output.NumBytesAvailable > 0) then begin
OutList:=TStringlist.create; OutList:=TStringlist.create;
try try
OutList.LoadFromStream(fPlayerProcess.Output); OutList.LoadFromStream(fPlayerProcess.Output);
if Assigned(fPlayerStatusEvent) then begin
for x := 0 to OutList.Count -1 do begin
msg:=OutList[x];
fPlayerStatusEvent(msg);
end;
end;
finally finally
OutList.free; OutList.free;
end; end;
end; end;
if fPlayerProcess.StdErr.NumBytesAvailable > 0 then begin if (fPlayerProcess <> nil) and (fPlayerProcess.StdErr.NumBytesAvailable > 0) then begin
ErrList:=TStringlist.create; ErrList:=TStringlist.create;
try try
ErrList.LoadFromStream(fPlayerProcess.Stderr); ErrList.LoadFromStream(fPlayerProcess.Stderr);
if Assigned(fPlayerErrorEvent) then begin
for x := 0 to ErrList.Count -1 do begin
msg:=ErrList[x];
fPlayerErrorEvent(msg);
end;
end;
finally finally
ErrList.free; ErrList.free;
end; end;
@ -251,6 +280,7 @@ begin
fMPlayerPath:='mplayer'+GetExeExt; fMPlayerPath:='mplayer'+GetExeExt;
fTimer:=TTimer.Create(Self); fTimer:=TTimer.Create(Self);
fTimer.Interval:=10;
fTimer.OnTimer:=@TimerEvent; fTimer.OnTimer:=@TimerEvent;
end; end;
@ -314,6 +344,9 @@ begin
fPlayerProcess:=TProcessUTF8.Create(Self); fPlayerProcess:=TProcessUTF8.Create(Self);
fPlayerProcess.Options:=fPlayerProcess.Options+[poUsePipes,poNoConsole]; fPlayerProcess.Options:=fPlayerProcess.Options+[poUsePipes,poNoConsole];
if FPlayerInfos then
fPlayerProcess.CommandLine:=ExePath+' -slave -noquiet -wid '+IntToStr(CurWindowID)+' '+StartParam+' '+StrToCmdLineParam(Filename)
else
fPlayerProcess.CommandLine:=ExePath+' -slave -quiet -wid '+IntToStr(CurWindowID)+' '+StartParam+' '+StrToCmdLineParam(Filename); fPlayerProcess.CommandLine:=ExePath+' -slave -quiet -wid '+IntToStr(CurWindowID)+' '+StartParam+' '+StrToCmdLineParam(Filename);
DebugLn(['TCustomMPlayerControl.Play ',fPlayerProcess.CommandLine]); DebugLn(['TCustomMPlayerControl.Play ',fPlayerProcess.CommandLine]);