zoukankan      html  css  js  c++  java
  • 循环播放音乐

    下面是源代码:

    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)+'RunLibT01.AVI') then
      begin
       MediaPlayer1.FileName:=(ExtractFilePath(Application.Exename)+'RunLibT01.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;

  • 相关阅读:
    linux指令大全
    strcpy.strcmp.strlen.strcat函数的实现
    推箱子
    头文件string.h里的函数
    SVN 版本控制工具
    Nodejs 学习
    JavaScript基础知识复习
    CSS3 学习小结
    JSP中 JSTL
    JSP中的EL语言
  • 原文地址:https://www.cnblogs.com/yzryc/p/6374712.html
Copyright © 2011-2022 走看看