Not sure if it's related to Ionic, but when the page is loaded I have a button that play a sound.
If I click on that button - the sound does play.
Then, I wanted to play the same sound from that button - but when the page is loaded, so when the page is loaded - sound will play, when you click on that button - same sound will play.
NotAllowedError: The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
I tried using ionViewDidEnter
, setTimeout
for 5 seconds ... but I'm keep getting this error msg of permission ...
UPDATE - MEI score
On purpose I set my permissions for Auto play sound: Block
for finding the right solution.
I can raise the MEI score according to the following statement:
On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously play video with sound.
This means: - if somewhere on previous pages - I made a sound - switching to any other page - will also trigger sounds. - Or a valid click ( that loads a silent sound just to "collect" the permissions ) - also does the trick ..
Counting on that - when loading the Ionic project for the first time, then home.page.ts
is being loaded, the trick here, is, when I click on the menu item for selecting an inner page to go to -> this is considered a valid click
event for allowing playing audio files - in which the sound which didn't work before ( because I kept refreshing the same page w/o any clicks ) - now works on page switch..
UPDATE for background music ( for video games )
Found this thread ... I think it's the only way How to make audio autoplay on chrome