Windows 如何在Delphi中播放wav文件?
Delphi中有哪些函数可用于播放声音文件?完整教程可从以下网址获得:Windows 如何在Delphi中播放wav文件?,windows,delphi,audio,Windows,Delphi,Audio,Delphi中有哪些函数可用于播放声音文件?完整教程可从以下网址获得: 它有点旧了。但是它应该可以工作。使用WIN32-API(Unit MMSystem)中的sndPlaySound函数: sndPlaySound('C:\Windows\Media\Tada.wav',SND\u ASYNC) 以下是最快的方法: uses MMSystem; procedure TForm1.Button1Click(Sender: TObject); begin sndPlaySound('C:\W
它有点旧了。但是它应该可以工作。使用WIN32-API(Unit MMSystem)中的sndPlaySound函数:
sndPlaySound('C:\Windows\Media\Tada.wav',SND\u ASYNC) 以下是最快的方法:
uses MMSystem;
procedure TForm1.Button1Click(Sender: TObject);
begin
sndPlaySound('C:\Windows\Media\Tada.wav',
SND_NODEFAULT Or SND_ASYNC Or SND_LOOP);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
sndPlaySound(nil, 0); // Stops the sound
end;
本页很好地解释了如何使用sndPlaySound函数以及如何将wav文件嵌入为资源: 简单:
procedure PlaySoundFile(FileName: string);
begin
if FileExists(FileName)
then PlaySound(pchar(FileName), 0, SND_ASYNC or SND_FILENAME);
{ Flags are:
SND_SYNC =0 = Start playing, and wait for the sound to finish
SND_ASYNC =1 = Start playing, and don't wait to return
SND_LOOP =8 = Keep looping the sound until another sound is played }
end;
人们也在引用sndPlaySound,但这只是为了向后兼容所以,不要使用它强>
您也可能对此感兴趣:
procedure PlayWinSound(SystemSoundName: string);
begin
Winapi.MMSystem.PlaySound(PChar(SystemSoundName), 0, SND_ASYNC);
end;
{ All available constants are defined in the registry under the path HKEY_CURRENT_USER -> AppEvents -> Schemes -> Apps -> .Default.
System sounds:
SystemEXCLAMATION - Note)
SystemHAND - Critical Stop)
SystemQUESTION - Question)
SystemSTART - Windows-Start)
SystemEXIT - Windows-Shutdown)
SystemASTERIX - Star)
RESTOREUP - Enlarge)
RESTOREDOWN - Shrink)
MENUCOMMAND - Menu)
MENUPOPUP - Pop-Up)
MAXIMIZE - Maximize)
MINIMIZE - Minimize)
MAILBEEP - New Mail)
OPEN - Open Application)
CLOSE - Close Application)
APPGPFAULT - Program Error)
Asterisk - played when a popup alert is displayed, like a warning message.
Calendar Reminder - played when a Calendar event is taking place.
Critical Battery Alarm - played when your battery reaches its critical level.
Critical Stop - played when a fatal error occurs.
Default Beep - played for multiple reasons, depending on what you do. For example, it will play if you try to select a parent window before closing the active one.
Desktop Mail Notif - played when you receive a message in your desktop email client.
Device Connect - played when you connect a device to your computer. For example, when you insert a memory stick.
Device Disconnect - played when you disconnect a device from your computer.
Device Connect Failed - played when something happened with the device that you were trying to connect.
Exclamation - played when you try to do something that is not supported by Windows.
Instant Message Notif - played when you receive an instant message.
Low Battery Alarm - played when the battery is running low.
Message Nudge - played when you receive a BUZZ in an instant message.
New Fax Notification - played when you receive a fax via your fax-modem.
New Mail Notification - played when you receive an email message.
New Text Message Notif - played when you receive a text message.
NFP Completion - played when the transfer of data via NFC between your Windows device and another device is completed.
NFP Connection - played when your Windows device is connecting to another device via NFC.
Notification - played when a default notification from a program or app is displayed.
System Notification - played when a system notification is displayed. }
链接不再是最新的了。很遗憾,但仍然可以通过archive.org访问它:很简单。使用MMsystem.PlaySound。像这样使用:播放声音(pchar(文件名),1,SND_异步或SND_文件名);sndPlaySound-为什么不使用它?你可以添加MSDN链接:那么为什么Embarcadero在他们最新的项目中仍然使用sndPlaySound呢?@ShaunRoselt在Delphi中仍然有大量的遗留代码。但在经历了大约15年的尖叫之后,Embarcadero听到了开发商的声音。看起来他们从Delphi Berlin update 1开始修复了大量的bug。在这个版本之前,他们只在Delphi中添加了bug:):)不要使用sndPlaySound。它的存在只是为了兼容性:sndPlaySound的存在只是为了向后兼容。这个过程在FireMonkey中有效吗?如果是,那么它会在其他非Windows平台上工作吗?SND_LOOP将播放歌曲无限时间SND播放声音仅用于向后兼容