Search code examples
javascriptwindowswinapielectrondesktop-application

How to play System Media Sounds


I'm developing an Desktop application using ElectronJS.

How can I play System Media sounds?

I know that for C# I can use

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

How can I do a similar call on ElectronJS?


Solution

  • As far as I am aware, there is no way to play a system sound using an Electron app directly. However, there are workarounds. You can ship with system sounds in your application and playing one depending on the OS your user is running, and shell beeps can be provided by importing shell from Electron and calling shell.beep();.

    Another alternative may be detecting what OS is being used and pointing your media player at the relevant system sound file. This can be done with a hidden window that includes an HTML5 media player.