Delphi MediaPlayer1 播放avi 视频


本文整理自网络,侵删。

 
delphitop.com 提示 本示例演示了TMediaPlayer组件的用法,假设表单上存在两个“打开”和“停止”按钮。注意:为了能够手动控制按钮,必须将“自动播放”设置为“false”。
procedure TForm2.btOpenClick(Sender: TObject);
var
  OpenMediaDialog : TOpenDialog;
begin
  OpenMediaDialog := TOpenDialog.Create(Self);
  OpenMediaDialog.Filter := 'All Video Files (*.avi)|*.avi';
  // Browse for .avi files on your computer
  if OpenMediaDialog.Execute() then
  begin
    { Assign a file to the media player. }
    MediaPlayer1.FileName := OpenMediaDialog.FileName;

    { Check if the file exists and is not a directory. }
    if (FileExists(OpenMediaDialog.FileName)) and
       (not DirectoryExists(OpenMediaDialog.FileName)) then
    begin
      { Open the files. }
      MediaPlayer1.Wait := true;
      MediaPlayer1.Open;
      MediaPlayer1.Play;

      { Override automatic button controlling. }
      MediaPlayer1.EnabledButtons :=
        [TMPBtnType.btPause, TMPBtnType.btStop, TMPBtnType.btPlay];

      { Enable the Stop button. }
      btStop.Enabled := true;
      btOpen.Enabled := false;
    end;
  end;

  OpenMediaDialog.Free;
end;

procedure TForm2.btStopClick(Sender: TObject);
begin
  { Stop and close the media. }
  MediaPlayer1.Stop;
  MediaPlayer1.Close;

  MediaPlayer1.EnabledButtons := [];

  { Enable Open button again. }
  btOpen.Enabled := true;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  { Disable all buttons. }
  MediaPlayer1.AutoEnable := false;
  MediaPlayer1.EnabledButtons := [];
end;

procedure TForm2.MediaPlayer1PostClick(Sender: TObject;
  Button: TMPBtnType);
begin
  if Button = TMPBtnType.btStop then
     btStop.Click;
end;

相关阅读 >>

Delphi post数据与对应的接收方式

Delphi fdquery遍历输出 json

Delphi配置文件ini

Delphi 动态数组的使用

Delphi中读写txt文件的一段代码

Delphi xe安装2010版控件

Delphi内存对齐

Delphi sysutils.strcat

Delphi 收集了比较全的字符串进制转换

win32全局钩子在Delphi下实现的关键技术

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...