中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Delphi > 综合文章
循环播放音乐
作者:未知 时间:2005-08-07 21:00 出处:编程爱好者网站 责编:chinaitpower
              摘要:循环播放音乐
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;

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有