HTML iframe allow autoplay of audio file not working safari - html

This works perfect with other browsers but safari automatically downloads file.
<iframe src="lib/audio/voice.mp3" allow="autoplay" class="audio-main" id="iframeAudio">
</iframe>
I need play background audio in a website. Opera and Chrome are working fine unfortunatelly Safari Browser open website automatically audio download.What exactly is the problem, Thanks for advance

No Auto-Play by default says the man
According to Safari / WebKit Auto-Play policy it gives users the ability to browse the web with fewer distractions, particularly in the form of relief from websites that auto-play with sound. They instruct websites to assume that any use of video or audio will require a user gesture or click to play.
Policy configuration
Users can enable auto play functionality on a per website bases.
Safari >> Preferences >> Websites >> Auto-Play
Options are:
Allow All Auto-Play
Stop Media with Sound (default)
Never Auto-Play
Functionality iframe allow autoplay works in Safari
When the user has allowed auto play from a specific website the iframe tag works as expected.
<iframe allow="autoplay" src="happy.mp3"></iframe>
Not surprising though so too does the <audio> element load and play on its own.
<audio autoplay loop src="happy.mp3"></audio>
Detect auto play is disabled and display player
However it should be expected that this functionality will not be enabled, since the ability exists for users to disable it, so it’s important to detect if auto play was denied and proactively react accordingly.
var promise = $('video')[0].play();
if (promise) promise.catch(error => {
// Auto-play disabled show controls
$('audio').attr('controls', '');
});
For this option we do not need auto play at all since we are manually calling play. This will not work of course if a user action is required so all we are left to do is to add the controls and display the player.
Audio with controls
For the sake of completion, there's always the other option; avoid auto play all together... but what's the fun in that.
<audio controls src="happy.mp3"></audio>
nJoy!

Related

Prevent autoplay of <video> elements

does someone know how to prevent Chrome and Safari from autoplaying videos? I am looking for an attribute or style I can incorporate into our website, not a browser extension! We have a few videos on the same page and in Chrome they just all start auto playing for some users while in Safari they kind of autoplay, but they don't start at the same time. They all have sound, so I had expected none of them to autoplay, but apparently that is not the case (at least not for all users).
Thanks!
Use autostart=0 and autostart=1
HTML embed autoplay="false", but still plays automatically
https://support.google.com/chrome/forum/AAAAP1KN0B0LkA8FoBoleU/?hl=en&gpf=%23!topic%2Fchrome%2FLkA8FoBoleU
Make sure you use the video or audio HTML5 elements, and NOT object or embed. I also had this problem using the latter HTML elements and the ONLY way to stop them from autoplaying was to change the browser settings. The reason is, because object and embed use a 3rd party plugin or player when playing your media, while video and audio are native to the browser.
If you want to stop them from playing anyway on just your box, below are the settings for Firefox:
Open up your Firefox Browser, click the menu button, and select "Options"
Select the "Privacy & Security" panel and scroll down to the "Permissions" section
Find "Autoplay" and click the "Settings" button. In the dropdown change it to block audio and video. The default is just
audio.

How to disable AirPlay button in Safari?

I'm trying to remove airplay button from native Safari video player on iOS and Mac and I was not able to find a working solution.
It seems imposible to disable it even though documentation says otherwise
I use an .m3u8 source for the video (an online stream from Wowza).
Safari ver. 12.1.1 on Mac, iOS 12.1
I have added x-webkit-wirelessvideoplaybackdisabled, x-webkit-airplay="deny" attributes.
https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_7_0.html#//apple_ref/doc/uid/TP40014305-CH5-SW6
I also set disableRemotePlayback on video element object to true but the airPlay button is still present.
https://www.w3.org/TR/remote-playback/#dom-htmlmediaelement-disableremoteplayback
...
const $video = $(`<video style="width: 100%; height: 100%" class="ios-video" controls autoplay muted playsinline x-webkit-airplay="deny" x-webkit-wirelessvideoplaybackdisabled>`);
$video[0].disableRemotePlayback = true;
$video[0].src = stream;
$(self.playerSelector).append($video);
...
I expect that there would be no AirPlay button, but unfortunately even so the webkitWirelessVideoPlaybackDisabled attribute on video element in js is set to true an AirPlay button is still present.
Opting Into or Out of AirPlay
Video playing in your app or from your website can be enabled for AirPlay or not, at your discretion.
In apps compiled with the base SDK set to iOS 5.0 and later, AirPlay is enabled by default; if you do not want iOS-based devices to be able to play your video over Apple TV, you must disable AirPlay explicitly.
To explicitly opt out of AirPlay, set x-webkit-airplay attribute for the video tag or the airplay attribute for the embed tag to "deny", as shown in Listing 2-2.
x-webkit-airplay="deny"
I know you said you did that in your question, but that is the solution according to Apple.

HLS / Media Source Extensions <video> with muted & autoplay freezes on first frame on mobiles

I attempted to add a Hero background video to our website. It's being served from mux.com.
I use it with HLS, but for Chrome it uses Media Source Extensions from what I gather.
I know that for HTML5 video to auto play, it has to be muted also, and I have both parameters over there.
Apparently, on Android Chrome I get behaviour where it freezes on the first frame (black), but doesn't continue and I cannot trace why.
In case of freezing, it still does load the video, just that it's not getting autoplayed.
I am out of clues.
Isolation sandbox:
https://codesandbox.io/s/32yky6x7mq
https://32yky6x7mq.codesandbox.io/
In my attempts, I have reduced this down to simple HTML app with Hls.js library and basic <video> tag where it breaks on mobiles.
How do I get the video to autoplay on mobiles?
P.S. To see exactly what I have tried, please see edit history, as I have been trying lots of things.
On my device specifically, Android Chrome, it's caused by Data Saver.
Disabling Data Saver, the video autoplays.
It's paradoxical, because with Data Saver I expect for the video to not be loaded at all, but it's getting loaded and the autoplay gets interrupted instead - resulting in more waste.
Possibly, there are other settings out there in the wild that prevent autoplay, for instance, couldn't find the exact reasons why iOS is not working. There are hints about playsinline attribute, which I have not tested yet. (Will update when I do)
Worth noting, is Feature-Policy header too: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
It didn't help me in my scenario, but it can probably be related with autoplay in other scenarios.

HTML video autoplay without muted (or how does youtube do it)?

I know that many newer browsers now disable autoplay when the video isn't muted or mute it and then play. Without user interaction it's also not possible to call play on a video. That's understandable, but I'm wondering how youtube is still able to start the videos with sound.
I checked and they do use the video tag, just not with any autoplay/muted attributes and loading some blob. It's not the user interaction opening the video, it also starts when opening a link in incognito mode.
So my conclusion, it should still be possible. But how? Or did browsers add some kind of exception for trusted video streaming sites?
Thanks in advance
For the Youtube case, it is probably a pre-populated white list
https://blog.google/products/chrome/improving-autoplay-chrome/
If you don’t have browsing history, Chrome allows autoplay for over 1,000 sites where we see that the highest percentage of visitors play media with sound.
For other generic cases, you can refer to the following rules (for Chrome at least)
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
Autoplay with sound is allowed if:
User has interacted with the domain (click, tap, etc.).
On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously play video with sound.
On mobile, the user has added the site to his or her home
screen.

HTML audio preload

I have a sound effect that I need to play whenever someone taps on something but the first tap sound always lags and then it's fine after that. I understand it should have something to do with the preload but I've had preload set to auto the entire time.
<audio id="effect" src="audio/bloop.mp3" preload="auto"></audio>
How can I get rid of that initial lag?
Incase you are using - Safari on iOS:
Preloading and on iOS devices is disabled to save bandwidth.
In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it.
Source: Safari Developer Library