一个Delphi中使用TMediaPlayer全屏播放的例子,做法挺简单的。需要在TForm上放置2个按钮,一个用来播放,一个用来关闭TForm。然后再放置一个 TMediaPlayer 和 TPanel 控件即可。
所有的属性都是在运行期设置的。代码如下:
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, MPlayer, StdCtrls; type TForm2 = class(TForm) MediaPlayer1: TMediaPlayer; Panel1: TPanel; Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin if MediaPlayer1.DeviceID<>0 then begin if (MediaPlayer1.Mode=mpplaying) then MediaPlayer1.Stop; end; MediaPlayer1.FileName:='md.wmv'; MediaPlayer1.Open; MediaPlayer1.Play; MediaPlayer1.DisplayRect:=Rect(0,0,Screen.Width,Screen.Height); end; procedure TForm2.Button2Click(Sender: TObject); begin Form2.Close; end; procedure TForm2.FormActivate(Sender: TObject); begin //设置Form没有边框 Form2.BorderStyle:=bsNone; end; procedure TForm2.FormCreate(Sender: TObject); begin //Form最大化 WindowState:=wsMaximized; //Panel也是最大化 Panel1.Align:=alClient; //设置播放显示在Panel1上 MediaPlayer1.Display:=Panel1; end; end.
默认情况下 XP 和 Windows7 至少要支持WMV ,下面是一个测试的视频
源代码和可执行文件下载