怎么播放WAV文件啊?(150分)

  • 主题发起人 主题发起人 sky_zzl
  • 开始时间 开始时间
S

sky_zzl

Unregistered / Unconfirmed
GUEST, unregistred user!
我在代码中写了PlaySound()函数并正确写好参数,并加上"mmsystem.h"后还是提示参数有错。我这样写的PlaySound("XXX.wav",NULL,SND_ASYNC);但编译不能通过,说参数有错。
各位有什么解决方法,越详细越好。
还有,我想在字符串末尾加上个回车的控制字符,以便在多行显示的Edit控件中自动每句字符串后换行,我就在每个CString后面加了'/n',可还是不能换行啊。我想是什么硬回车和软回车的区别,可我不懂,能告诉我该怎么解决吗?
以上2问题只要能回答一道我都给分!谢谢各位朋友。
 
(*******************************************************************************
**
** This example was derived to overcome the deficiencies of using just the
** 'sndPlaySound' function. The 'sndPlaySound' is ideal and easy to use to
** play WAV files synchronously. It allows asynchronous playing of WAV files
** as well, but there is no method of notifying the host when the sound has
** completed playing. This example was put together after studying the
** MMSYSTEM.PAS unit, and articles on the MSCDN.
**
** Andy Strong - Compuserve ID : 100716,3015
** Internet Address: andrews@nbaqsl.co.uk
**
** Released into the publicdo
main 09/05/96
**
** Controls:
** This code may be used, modified, included in applications without any
** license agreements as long as the disclaimers are accepted - ie FREEWARE
**
** Disclaimer:
** This software is released into the publicdo
main on the strict understanding
** that neither myself nor any associates or companies I work for have any
** liability explictly or implied.
**
*******************************************************************************)
unit Mciplay1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, MMSystem;
const
WAVFILENAME = 'C:/WINDOWS/CHIMES.WAV';
{ WAV file to play }
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
wDeviceID: word;
public
{ Public declarations }
procedure MMMCNotify(var Msg: TMessage);
message MM_MCINOTIFY;
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
mciOpenParms: TMCI_Open_Parms;
mciPlayParms: TMCI_Play_Parms;
begin
if waveOutGetNumDevs < 1 then
{ Any devices? }
ShowMessage('No wave devices available!')
else
begin
FillChar(mciOpenParms,
SizeOf(TMCI_Open_Parms), 0);
FillChar(mciPlayParms,
SizeOf(TMCI_Play_Parms), 0);
with mciOpenParmsdo
{ Set MCI to play WAV files }
begin
lpStrDeviceType := 'waveaudio';
lpstrElementName := WAVFILENAME;
end;
if mciSendCommand(0, MCI_OPEN,
MCI_OPEN_TYPE or MCI_OPEN_ELEMENT,
Longint(@mciOpenParms)) = 0 then
{ Open Device }
begin
wDeviceID := mciOpenParms.wDeviceID;
{ Grab Device ID for later }
mciPlayParms.dwCallback := Handle;
{ Set our Handle for Callback message }
mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY,
LongInt(@mciPlayParms));
{ Kick off play of File;
await message }
end;
end;
end;

procedure TForm1.MMMCNotify(var Msg: TMessage);
begin
inherited;
{ Normal processing for message }
ShowMessage('Sound play complete!');
mciSendCommand(wDeviceID,
MCI_CLOSE, 0, 0);
{ Close device now its finished }
end;

end.
 
播放文件需加上SND_FILENAME参数
PlaySound("XXX.wav",NULL,SND_ASYNC &amp;
SND_FILENAME);
 
加上"mmsystem.h"
sndPlaySound(filename,SND_ASYNC|SND_LOOP);
在project菜单setting下,弹出对话框
选择link标签,在object/libary modules里输入"winmm.lib",点ok
运行
 
2软回车是自动换行,例如在一个表格中,输入一定的字符后自动换行,WORD中也一样。
硬回车是手动换行,即按回车符换行。
 
用控件呀
 
#include <windows.h>
#include <mmsystem.h>
#pragma comment (lib,"WINMM.LIB")
void main(void)
{
if (sndPlaySound("C://Program Files//shanda//Legend of Mir//Wav//1360-1.wav",SND_FILENAME))
MessageBox(NULL, "suff", "suff", NULL);
}
 
恩,感谢zzb1984和amli,问题解决了
 

Similar threads

后退
顶部