In this article, we will see how to play video in the electron app with sound using HTML 5 video element. Chromium restricts webpages to auto-play video with sound. As Electron app use chrome behind the scene this restriction does apply to the Electron app. But Electron app is used to build a desktop app and you might need to override this behavior.
With electron 5.0.0, you can use the autoplay-policy attribute to override the autoplay policy. This attribute can be set to no-user-gesture-required or user-gesture-required. The default value is no-user-gesture-required.
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required")
Turning off web security in electron
If you are using electron 4.0.0 or below, you can turn off web security to play videos with sound. This is not recommended as it will turn off web security for all the web pages.
mainWindow = new BrowserWindow({
webPreferences: {
webSecurity: false
}
})