Как воспроизвести wav-файл в Delphi? - PullRequest
18 голосов
/ 29 октября 2008

Какие функции доступны в Delphi для воспроизведения звукового файла?

Ответы [ 5 ]

27 голосов
/ 29 октября 2008

Вот самый быстрый способ:

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;
4 голосов
/ 30 октября 2008

Эта страница довольно хорошо объясняет, как использовать функцию sndPlaySound и как встроить wav-файл в качестве ресурса: http://www.latiumsoftware.com/en/delphi/00024.php

4 голосов
/ 29 октября 2008

С функцией sndPlaySound из WIN32-API (Unit MMSystem):

sndPlaySound ('C: \ Windows \ Media \ Tada.wav', SND_ASYNC);

3 голосов
/ 18 апреля 2016

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;

Люди также цитируют 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.  }
2 голосов
/ 29 октября 2008

Полный учебник доступен по адресу: http://sheepdogguides.com/dt3f.htm

Это немного старо. Но это должно сработать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...