I have audio/videos that you can play in a portfolio area on my website. If I play one of them, and then go the previous page, and then back to my page using next button of my browser, the audio will play automatically even though I didn't click on anything. The exact same behaviour will occur if I play a video or audio, click to visit another page, and then click on the previous page button of my browser.
How could I prevent that?
Here's some code :
<iframe class="ms-slide-video" src="about:blank" allowfullscreen="true" style="width: 100%; height: 100%; display: none;"></iframe>
Gets transformed to :
<iframe class="ms-slide-video" src="/dacontent/video/mp4/2205.mp4?&autoplay=1" allowfullscreen="true" style="width: 100%; height: 100%; display: block; opacity: 1;"></iframe>
When I click on play.
But when the bug occurs, the iframe's src stays "about:blank".
Here's the iframe content at all time :
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body>
<video controls="" autoplay="" name="media">
<source src="http://www.kang.fr/dacontent/video/mp4/2205.mp4?&autoplay=1" type="video/mp4"></video>
</body>
</html>
I found and tried removing "&autoplay=1" in the src attribute of source, with no success. Couldn't find out how to change video's autoplay attribute though.
The audio tag allows you to embed audio content in your HTML pages. By default the browser does not show any controls for this element. Which means the audio will play only if set to autoplay (more on this later) and the user can't see how to stop it, or control the volume or move through the track.
The simplest way to automatically play content is to add the autoplay attribute to your <audio> or <video> element.
Chrome's autoplay policies are simple: Muted autoplay is always allowed. Autoplay with sound is allowed if: The user has interacted with the domain (click, tap, etc.).
I have resolved my issue.
First, as I said :
But when the bug occurs, the iframe's src stays "about:blank".
This was wrong. My browser inspector was blatantly lying to me about those iframes. Actually, the src attribute was filled with the video link.
So I had to empty the attribute of those iframes, but only when the page was fully loaded. Before that, it wouldn't be any use because the iframes were not generated yet.
Here's the final code (it is specific to Masterslider's slides, but will work for any iframe that causes this problem).
jQuery(window).load(function ($) {
if (jQuery('iframe.ms-slide-video').length) {
jQuery('iframe.ms-slide-video').attr('src', '');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With