初学MCI(50分)

  • 主题发起人 主题发起人 gxdx
  • 开始时间 开始时间
G

gxdx

Unregistered / Unconfirmed
GUEST, unregistred user!
为何发不出声????????

unit Sound;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var filename:string;
var returnstr,commandstr:pchar;
begin

commandstr:=StrAlloc(131);
returnstr:=stralloc(131);
if OpenDialog1.Execute then

begin

filename:=OpenDialog1.filename;
commandstr:=PChar('Open '+filename+' type wavaudio alias sounds');
// showMessage(commandstr);
mciSendString(commandstr,returnstr,131,0);
commandstr:=Pchar('Play sounds' );
mciSendString(commandstr,returnstr,131,0);
end;

end;


end.
 
播放背景音乐

如果要做一些比较艺术化的程序时,你会想到插入背景音乐,这时你是否使用了TMediaPlayer控件来播放音乐呢?其实我们大可放弃该方法,直接使用WINDOWS为 我们提供的API函数来播放音乐,方法如下:首先需要在uses部分加入mmsystem,接着写入下列语句,其中e:/1.mid为播放的文件,NN为自定义名称标志

procedure TForm1.Button1Click(Sender: Tobject);
begin

//播放音乐
MCISendString(
'OPEN e:/1.MID TYPE SEQUENCER ALIAS NN',
'', 0, 0);
MCISendString('PLAY NN FROM 0', '', 0, 0);
MCISendString('CLOSE ANIMATION', '', 0, 0);
end;


procedure TForm1.Button2Click(Sender: Tobject);
begin

//停止播放
MCISendString(
'OPEN e:/1.MID TYPE SEQUENCER ALIAS NN',
'', 0, 0);
MCISendString('STOP NN', '', 0, 0);
MCISendString('CLOSE ANIMATION', '', 0, 0);
end;


 
还是不行哦。是不是跟初始化有关啊?
 

Similar threads

I
回复
0
查看
740
import
I
I
回复
0
查看
452
import
I
I
回复
0
查看
686
import
I
I
回复
0
查看
529
import
I
后退
顶部