I'm working on an Electron app
with Angular 4. I want to play sound on some specific action. Is there any module or code for that? It can be in the angular 4 or if electron is providing some service for that it should also work
As I want to play it on some action I can't use the HTML audio tag and audio() of javascript
I only want to play the sound of 2-3 seconds so no other functionalities are needed.
It can be of electron or Angular 4 any of them can work...
As per Robin's comment, i have checked that link we can use it using the audio() object in the ts file like this:
You could try using howler.js
You can install it to your project with
npm install --save howler
and play a sound like this:just did this in a project am working (angular 4) and it worked
make sure the path is correct and references an existing audio
updated: I had the same problem and used ViewChild reference with ElementRef to solve this.
app.component.ts
app.component.html
The Asmon code is good, but I think that the real problem is that the Google Chrome policy was updated, on this page https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio you can find The answer In summary, the focus should be on this.
Chrome's autoplay policies are simple: