本文整理自网络,侵删。
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》频道 >>