windows 如何在 Delphi 中播放 wav 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/246723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to play a wav-File in Delphi?
提问by Name
Which functions are available within Delphi to play a sound-file?
Delphi 中可以使用哪些函数来播放声音文件?
回答by Igal Tabachnik
Here's the fastest way:
这是最快的方法:
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;
回答by Name
With the function sndPlaySound from the WIN32-API (Unit MMSystem):
使用 WIN32-API(单位 MMSystem)中的 sndPlaySound 函数:
sndPlaySound('C:\Windows\Media\Tada.wav', SND_ASYNC);
sndPlaySound('C:\Windows\Media\Tada.wav', SND_ASYNC);
回答by Name
This page explains quite good how to use the function sndPlaySound and how to embed the wav-file as a resource: http://www.latiumsoftware.com/en/delphi/00024.php
这个页面很好地解释了如何使用函数 sndPlaySound 以及如何将 wav 文件作为资源嵌入:http: //www.latiumsoftware.com/en/delphi/00024.php
回答by Migrate2Lazarus see my profile
Simple:
简单的:
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;
People are also quoting sndPlaySound but this is for backward compatibility only. So, don't use it!
人们也引用了 sndPlaySound 但这只是为了向后兼容。所以,不要使用它!
You may also be interested in this:
您可能还对此感兴趣:
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. }
回答by Toon Krijthe
A full tutorial is available at: http://sheepdogguides.com/dt3f.htm
完整教程位于:http: //sheepdogguides.com/dt3f.htm
It is a bit old. But it should work.
它有点旧了。但它应该工作。