• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

循环播放音乐_Delphi

Delphi 搞代码 3年前 (2018-08-09) 161次浏览 已收录 0个评论

unit Unit1;

interface

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

type
TForm1 = class(TForm)

http://www.gaodaima.com/?p=65903循环播放音乐_Delphi

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;

欢迎大家阅读《循环播放音乐_Delphi,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址