TMediaPlayer

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
MPlayer, StdCtrls;

type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure MediaPlayer1Notify(Sender: TObject);
procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
with MediaPlayer1     do
begin
if Notify and //接受信息
(mode=mpStopped) then//已经停止
begin
ReWind;
play;
end;
notify:=true;//开始接受信息
end;

end;

procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
begin
if (Button=btStop) or (Button=btPause) then
MediaPlayer1.Notify:=false
else
MediaPlayer1.Notify:=true;  
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
with MediaPlayer1     do
begin
fileName:=OpenDialog1.FileName;
notify:=true;
try
open;
play;
except
raise exception.Create('打开文件时出错');
end;
caption:='循环播放演示-->'+fileName;
end;
end;

end.
窗体As text代码  
object Form1: TForm1
Left = 195
Top = 107
Width = 378
Height = 182
Caption = '循环播放演示'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object MediaPlayer1: TMediaPlayer
Left = 24
Top = 16
Width = 298
Height = 33
TabOrder = 0
OnClick = MediaPlayer1Click
OnNotify = MediaPlayer1Notify
end
object Button1: TButton
Left = 193
Top = 104
Width = 129
Height = 33
Caption = '打开...'
Default = True
TabOrder = 1
OnClick = Button1Click
end
object OpenDialog1: TOpenDialog
Title = '打开音乐文件'
Left = 294
Top = 32
end
end


if FileExists(ExtractFilePath(Application.Exename)+'RunLib\T01.AVI') then
begin
MediaPlayer1.FileName:=(ExtractFilePath(Application.Exename)+'RunLib\T01.AVI');
MediaPlayer1.Open;
MediaPlayer1.Notify:=true;
MediaPlayer1.Display:=Form2;
MediaPlayer1.DisplayRect:=Form2.ClientRect;
MediaPlayer1.Play;
end;

然后如下让它循环
procedure TForm2.MediaPlayer1Notify(Sender: TObject);
begin
if MCIStop=1 then Exit;
if MediaPlayer1.Mode=mpStopped then
begin
MediaPlayer1.Rewind;
MediaPlayer1.Play;
end;
MediaPlayer1.Notify:=true;
end;

转载于:https://www.cnblogs.com/aquar/archive/2008/04/29/3451545.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值