春光无限好 發表於 2021-6-17 17:54:00

Delphi中MediaPlayer简单使用--播放视频

<p>------------------</p>
<p><img src="https://img2020.cnblogs.com/blog/811422/202106/811422-20210617175524560-734044655.png"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>仅做简单的测试,只想看看怎么播放视频,不想弄这个,有兴趣的可以深入了解,谢谢!</p>
<p>要想更深入了解请参考:Delphi多媒体设计之TMediaPlayer组件(一) - pchmonster - 博客园&nbsp; https://www.cnblogs.com/pchmonster/archive/2012/07/12/2588846.html</p>
<p>--------------------</p>
<p>---------------------------Unit1 开始------------</p>
<p>unit Unit1;</p>
<p>interface</p>
<p>uses<br>Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>Dialogs, StdCtrls, MPlayer, ComCtrls, ExtCtrls;</p>
<p>type<br>TForm1 = class(TForm)<br>    MediaPlayer1: TMediaPlayer;<br>    Animate1: TAnimate;<br>    Button1: TButton;<br>    Panel1: TPanel;<br>    Timer1: TTimer;<br>    Label1: TLabel;<br>    procedure Button1Click(Sender: TObject);<br>    procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;<br>      var DoDefault: Boolean);<br>    procedure Timer1Timer(Sender: TObject);<br>    procedure FormCreate(Sender: TObject);<br>private<br>    { Private declarations }<br>public<br>    { Public declarations }<br>end;</p>
<p>var<br>Form1: TForm1;</p>
<p>implementation<br>var<br>    uDisplayRect:TRect;</p>
<p>{$R *.dfm}</p>
<p>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>//这个cool.avi在delphi7的安装目录下<br>MediaPlayer1.FileName:='C:\Program Files\Borland\Delphi7\Demos\CoolStuf\cool.avi' ;<br>end;</p>
<p>procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;<br>var DoDefault: Boolean);<br>begin<br>if Button=btPlay then //case Button of btPlay:begin (代码) end; end;比较好<br>begin<br>    MediaPlayer1.Open;//打开设备,还有对应的Close关闭设备<br>    MediaPlayer1.DisplayRect:=uDisplayRect; //设置显示范围(本人设置的这个范围有点大了,视频失真)<br>    MediaPlayer1.Play;//播放<br>end;<br>{case Button of<br>   btPlay:<br>   begin<br>       MediaPlayer1.Open;//打开设备,还有对应的Close关闭设备<br>       MediaPlayer1.DisplayRect:=uDisplayRect; //设置显示范围(本人设置的这个范围有点大了,视频失真)<br>       MediaPlayer1.Play;//播放<br>   end;<br>end; }<br>end;</p>
<p>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>Label1.Caption:=IntToStr(MediaPlayer1.Position);<br>end;</p>
<p>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>uDisplayRect.Top:=10;<br>uDisplayRect.Left:=10;<br>uDisplayRect.Right:=500;<br>uDisplayRect.Bottom:=300;<br>MediaPlayer1.Display:=Panel1; //设置视频显示的地方(这里显示在panel上)<br>//Devicetype这个很重要,不要乱设置<br>end;</p>
<p>end.</p>
<p>&nbsp;</p>
<p>-----------------------Unit1 结束-------------</p>
<p>----------------Form1&nbsp; 开始----------</p>
<p>object Form1: TForm1<br>Left = 373<br>Top = 261<br>Width = 728<br>Height = 553<br>Caption = 'Form1'<br>Color = clBtnFace<br>Font.Charset = DEFAULT_CHARSET<br>Font.Color = clWindowText<br>Font.Height = -11<br>Font.Name = 'MS Sans Serif'<br>Font.Style = []<br>OldCreateOrder = False<br>OnCreate = FormCreate<br>PixelsPerInch = 96<br>TextHeight = 13<br>object Label1: TLabel<br>    Left = 144<br>    Top = 480<br>    Width = 129<br>    Height = 13<br>    AutoSize = False<br>    Caption = 'Label1'<br>end<br>object MediaPlayer1: TMediaPlayer<br>    Left = 136<br>    Top = 424<br>    Width = 253<br>    Height = 30<br>    AutoEnable = False<br>    AutoRewind = False<br>    FileName = 'C:\Program Files\Borland\Delphi7\Demos\CoolStuf\cool.avi'<br>    TabOrder = 0<br>    OnClick = MediaPlayer1Click<br>end<br>object Animate1: TAnimate<br>    Left = 528<br>    Top = 440<br>    Width = 65<br>    Height = 57<br>end<br>object Button1: TButton<br>    Left = 40<br>    Top = 424<br>    Width = 75<br>    Height = 25<br>    Caption = 'Button1'<br>    TabOrder = 2<br>    OnClick = Button1Click<br>end<br>object Panel1: TPanel<br>    Left = 16<br>    Top = 16<br>    Width = 665<br>    Height = 377<br>    TabOrder = 3<br>end<br>object Timer1: TTimer<br>    Interval = 100<br>    OnTimer = Timer1Timer<br>    Left = 64<br>    Top = 472<br>end<br>end</p>
<p>&nbsp;</p>
<p>---------------Form1 结束---------------</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/dmqhjp/p/14894692.html
頁: [1]
查看完整版本: Delphi中MediaPlayer简单使用--播放视频