mplayer: fixed default mplayer filename, less hints

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2921 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
mgaertner
2014-03-26 01:22:03 +00:00
parent 23207df1a1
commit 4fe58ed1e4

View File

@ -45,7 +45,8 @@ interface
uses uses
Classes, SysUtils, Controls, WSLCLClasses, LCLProc, LCLType, InterfaceBase, Classes, SysUtils, Controls, WSLCLClasses, LCLProc, LCLType, InterfaceBase,
LResources, LMessages, Graphics, ExtCtrls, FileUtil, Process, UTF8Process LResources, LMessages, Graphics, ExtCtrls, FileUtil, Process, UTF8Process,
LazFileUtils
{$ifdef Linux} {$ifdef Linux}
, gtk2int, gtk2, glib2, gdk2x, Gtk2WSControls, GTK2Proc, Gtk2Def , gtk2int, gtk2, glib2, gdk2x, Gtk2WSControls, GTK2Proc, Gtk2Def
{$endif} {$endif}
@ -117,12 +118,12 @@ type
{ TWSMPlayerControl } { TWSMPlayerControl }
{$ifdef Linux} {$ifdef Linux}
TWSMPlayerControl = class(TGtk2WSWinControl) TWSMPlayerControl = class(TGtk2WSWinControl)
published published
class function CreateHandle(const AWinControl: TWinControl; class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override; const AParams: TCreateParams): HWND; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override; class procedure DestroyHandle(const AWinControl: TWinControl); override;
end; end;
{$endif} {$endif}
procedure Register; procedure Register;
@ -139,18 +140,24 @@ end;
procedure TCustomMPlayerControl.TimerEvent(Sender: TObject); procedure TCustomMPlayerControl.TimerEvent(Sender: TObject);
var var
OutList, ErrList:TStringlist; OutList, ErrList:TStringlist;
begin begin
if Running then begin if Running then begin
if fPlayerProcess.Output.NumBytesAvailable > 0 then begin if fPlayerProcess.Output.NumBytesAvailable > 0 then begin
OutList:=TStringlist.create; OutList:=TStringlist.create;
OutList.LoadFromStream(fPlayerProcess.Output); try
OutList.free; OutList.LoadFromStream(fPlayerProcess.Output);
finally
OutList.free;
end;
end; end;
if fPlayerProcess.Output.NumBytesAvailable > 0 then begin if fPlayerProcess.StdErr.NumBytesAvailable > 0 then begin
ErrList:=TStringlist.create; ErrList:=TStringlist.create;
ErrList.LoadFromStream(fPlayerProcess.Stderr); try
ErrList.free; ErrList.LoadFromStream(fPlayerProcess.Stderr);
finally
ErrList.free;
end;
end; end;
end else begin end else begin
Stop; Stop;
@ -197,7 +204,7 @@ begin
if FFilename=AValue then exit; if FFilename=AValue then exit;
FFilename:=AValue; FFilename:=AValue;
if Running then if Running then
SendMPlayerCommand('loadfile '); SendMPlayerCommand('loadfile '+StrToCmdLineParam(Filename));
end; end;
procedure TCustomMPlayerControl.SetLoop(const AValue: integer); procedure TCustomMPlayerControl.SetLoop(const AValue: integer);
@ -242,7 +249,7 @@ begin
FCompStyle:=csNonLCL; FCompStyle:=csNonLCL;
SetInitialBounds(0, 0, 160, 90); SetInitialBounds(0, 0, 160, 90);
fMPlayerPath:='mplayer'; fMPlayerPath:='mplayer'+GetExeExt;
fTimer:=TTimer.Create(Self); fTimer:=TTimer.Create(Self);
fTimer.OnTimer:=@TimerEvent; fTimer.OnTimer:=@TimerEvent;
end; end;
@ -271,7 +278,7 @@ end;
procedure TCustomMPlayerControl.Play; procedure TCustomMPlayerControl.Play;
var var
ExePath: String; ExePath: String;
CurWindowID: int64;//TXID; CurWindowID: PtrUInt;
begin begin
if (csDesigning in ComponentState) then exit; if (csDesigning in ComponentState) then exit;
@ -291,26 +298,27 @@ begin
FreeAndNil(fPlayerProcess); FreeAndNil(fPlayerProcess);
// raise Exception.Create('TCustomMPlayerControl.Play fPlayerProcess still exists'); // raise Exception.Create('TCustomMPlayerControl.Play fPlayerProcess still exists');
if MPlayerPath='' then
MPlayerPath:='mplayer'+GetExeExt;
ExePath:=MPlayerPath; ExePath:=MPlayerPath;
if not FilenameIsAbsolute(ExePath) then if not FilenameIsAbsolute(ExePath) then
ExePath:=FindDefaultExecutablePath(ExePath); ExePath:=FindDefaultExecutablePath(ExePath);
if not FileExistsUTF8(ExePath) then if not FileExistsUTF8(ExePath) then
raise Exception.Create('mplayer not found'); raise Exception.Create(MPlayerPath+' not found');
{$IFDEF Linux} {$IFDEF Linux}
CurWindowID := GDK_WINDOW_XWINDOW(PGtkWidget(PtrUInt(Handle))^.window); CurWindowID := GDK_WINDOW_XWINDOW({%H-}PGtkWidget(PtrUInt(Handle))^.window);
{$else} {$else}
CurWindowID := Handle; CurWindowID := Handle;
{$ENDIF} {$ENDIF}
fPlayerProcess:=TProcessUTF8.Create(Self); fPlayerProcess:=TProcessUTF8.Create(Self);
fPlayerProcess.Options:=fPlayerProcess.Options+[poUsePipes,poNoConsole]; fPlayerProcess.Options:=fPlayerProcess.Options+[poUsePipes,poNoConsole];
fPlayerProcess.CommandLine:=ExePath+' -slave -quiet -wid '+IntToStr(CurWindowID)+' '+StartParam+' "'+Filename+'"'; fPlayerProcess.CommandLine:=ExePath+' -slave -quiet -wid '+IntToStr(CurWindowID)+' '+StartParam+' '+StrToCmdLineParam(Filename);
DebugLn(['TCustomMPlayerControl.Play ',fPlayerProcess.CommandLine]); DebugLn(['TCustomMPlayerControl.Play ',fPlayerProcess.CommandLine]);
fPlayerProcess.Execute; fPlayerProcess.Execute;
fTimer.Enabled:=true; fTimer.Enabled:=true;
end; end;
procedure TCustomMPlayerControl.Stop; procedure TCustomMPlayerControl.Stop;
@ -340,7 +348,7 @@ begin
end; end;
{$ifdef Linux} {$ifdef Linux}
function MPLayerWidgetDestroyCB(Widget: PGtkWidget; data: gPointer): GBoolean; cdecl; function MPLayerWidgetDestroyCB(Widget: PGtkWidget; {%H-}data: gPointer): GBoolean; cdecl;
begin begin
FreeWidgetInfo(Widget); // created in TWSMPlayerControl.CreateHandle FreeWidgetInfo(Widget); // created in TWSMPlayerControl.CreateHandle
Result:=false; Result:=false;
@ -364,7 +372,7 @@ begin
WidgetInfo^.LCLObject := AWinControl; WidgetInfo^.LCLObject := AWinControl;
WidgetInfo^.Style := AParams.Style; WidgetInfo^.Style := AParams.Style;
WidgetInfo^.ExStyle := AParams.ExStyle; WidgetInfo^.ExStyle := AParams.ExStyle;
WidgetInfo^.WndProc := PtrUInt(AParams.WindowClass.lpfnWndProc); WidgetInfo^.WndProc := {%H-}PtrUInt(AParams.WindowClass.lpfnWndProc);
// set allocation // set allocation
Allocation.X := AParams.X; Allocation.X := AParams.X;
@ -381,7 +389,7 @@ begin
g_signal_connect(GPointer(NewWidget), 'destroy', g_signal_connect(GPointer(NewWidget), 'destroy',
TGTKSignalFunc(@MPLayerWidgetDestroyCB), WidgetInfo); TGTKSignalFunc(@MPLayerWidgetDestroyCB), WidgetInfo);
end; end;
Result:=HWND(PtrUInt(Pointer(NewWidget))); Result:=HWND({%H-}PtrUInt(Pointer(NewWidget)));
DebugLn(['TWSMPlayerControl.CreateHandle ',dbgs(NewWidget)]); DebugLn(['TWSMPlayerControl.CreateHandle ',dbgs(NewWidget)]);
end; end;
end; end;