Selecting sounds from Windows and playing them

前端 未结 3 1155
说谎
说谎 2021-02-19 16:01

I have a WinForms app. This app has a Preferences section where the user will be able to select which sounds are played when an alert is being displayed.

Is it possible

3条回答
  •  时光取名叫无心
    2021-02-19 16:42

    You do not require any API to play system sounds just write code like this:

    // Plays the sound associated with the Asterisk system event.
    System.Media.SystemSounds.Asterisk.Play();
    

    The SystemSounds class contains the following predefined system sounds:

    • Asterisk
    • Beep
    • Exclamation
    • Hand
    • Question

    All other sounds require you read the desired sound from the registry and play it with code like this:

    SoundPlayer simpleSound = new SoundPlayer(@"c:\Path\To\Your\Wave\File.wav");
    

提交回复
热议问题