Resize MediaPlayer without play button controls
I wanted to code a resizeable WindowsMediaplayer (ActiveX) wit开发者_JAVA技巧hout the play controls. it should fit to TPanels.
I had to work this out a while ago, and after lots of googling i found this to work
Put a WindowsMedaiPlayer object on the Panel, and setting its align to alclient,
the player control area can be hidden with uiMode := 'none'
, set in the ide or code
then assigning the Panels resize event with
uses Ole2;
procedure TForm1.Panel1Resize(Sender: TObject);
const
IID_IOleInPlaceObject: SYSTEM.TGUID = '{00000113-0000-0000-C000-000000000046}';
var
IOIPObj: IOleInPlaceObject;
begin
SYSTEM.IDispatch(WindowsMediaPlayer1.OleObject).QueryInterface(IID_IOleInPlaceObject, IOIPObj);
IOIPObj.SetObjectRects(Panel1.ClientRect, Panel1.ClientRect);
end;
procedure TForm1.Play;
begin
WindowsMediaPlayer1.uiMode := 'none'; //show no interface, this can be set from the ide
WindowsMediaPlayer1.URL := 'movie.mpg';
WindowsMediaPlayer1.stretchToFit := True;
WindowsMediaPlayer1.Controls.play;
end;
Adapted from http://our.obor.us/node/1999
Ole2 is for IOleInPlaceObject, i had to add $(Delphi)\source\rtl\Win
to the library path for delphi to find it.
(delphi 7, wmp 11)
Extra: Something a bit easier to use
uses Ole2;
procedure SmoothResizeMediaPlayer(aMediaPlayer: TWindowsMediaPlayer; PosRect,ClipRect:Trect);
const
IID_IOleInPlaceObject: SYSTEM.TGUID = '{00000113-0000-0000-C000-000000000046}';
var
IOIPObj: IOleInPlaceObject;
begin
SYSTEM.IDispatch(aMediaPlayer.OleObject).QueryInterface(IID_IOleInPlaceObject, IOIPObj);
IOIPObj.SetObjectRects(PosRect, ClipRect);
end;
and Called with
SmoothResizeMediaPlayer(WindowsMediaPlayer1, panel1.ClientRect, panel1.ClientRect);
精彩评论