在delphi5.0中如何使用api循环播放midi音乐,avi动画?

wmstudio 2000-08-23 11:26:00
在delphi5.0中播放音乐,总是用mediaplay控件,但其功能有些不足,而相关资料有很少,几乎少的可怜,而delphi5.0中如何使用api循环播放midi音乐,avi动画,我又百思不得其解,这个问题真的是比较偏门吗?
...全文
185 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Icebird 2001-04-25
  • 打赏
  • 举报
回复
下面是源代码:

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;
jiangtao 2000-08-24
  • 打赏
  • 举报
回复
mediaplayer就可以循环播放呀,而且功能很强大

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧