hebrerillo
Active Coder
Hello there!
I am having trouble playing videos with sound in Safari. The videos are not played by a click, but when they are visible on the screen by using an Intersection Observer.
In Firefox, once there has been some user interaction with the page, a click for example, I can do this:
And the video will be played with sound. But in Safari it will not be played and will raise a "NotAllowedError" exception.
The only way to play a video with sound in Safari, is to place the previous instruction in a click handler. For example, in the click event of a button:
Is there any other way to play a video with sound in Safari?
One more question. It will be also helpful if I can play the video with sound on load. For example, Youtube shorts can be played with sound on first page load in Safari. How??
I am having trouble playing videos with sound in Safari. The videos are not played by a click, but when they are visible on the screen by using an Intersection Observer.
In Firefox, once there has been some user interaction with the page, a click for example, I can do this:
Code:
document.querySelector('video').play();
The only way to play a video with sound in Safari, is to place the previous instruction in a click handler. For example, in the click event of a button:
Code:
button.addEventListener('click', () => document.querySelector('video').play());
One more question. It will be also helpful if I can play the video with sound on load. For example, Youtube shorts can be played with sound on first page load in Safari. How??