Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing Audio in Electron from main process

im developing an electron app, which needs to play a sound in case of incoming message from webSocket connection. The websocket is handled on the main process, as the user switches pages during usage. I can not play the sound from the renderer, as i don't know in which page the user is at the moment, the webSocket message comes in (in worst case he is in between to pages while navigating).

Is there chance to play back audio on main process? The audio file is stored locally within the project file structure.

Kind regards,

BoxSon

like image 221
MadMaxAPP Avatar asked Mar 09 '20 13:03

MadMaxAPP


People also ask

What is main electron process?

The main process​ Each Electron app has a single main process, which acts as the application's entry point. The main process runs in a Node. js environment, meaning it has the ability to require modules and use all of Node.

How do electrons run in the background?

Keeping Electron App in BackgroundListen to the window-all-closed event on app and to not quit the app, but instead hide all the renderer windows and the icon in the dock. Create or simply keep the Tray menu. Recreate a window when the users ask for it from the tray menu.

Does electron support HTML5?

Electron. js is a runtime framework that allows the user to create desktop-suite applications with HTML5, CSS, and JavaScript.


1 Answers

Found a workaround to solve this by my own:

  • create and open a hidden window.
  • In this window load a HTML5 audio player
  • via IPC send message to this hidden window from main to play a sound.

Little bit of effort but works like a charm.

Don't forget to destroy the hidden window on application closure (application won't close if you forget this step).

like image 97
MadMaxAPP Avatar answered Oct 05 '22 12:10

MadMaxAPP