lwm
lwm

Reputation: 192

Stop iframe autoplaying with mp4 files

I want to stop a .mp4 file in an iframe from autoplaying.

The code is simple:

var siteVidUrl = document.createElement("iframe");  // create iframe
siteVidUrl.src = Obj.URL + "?autoplay=0"; // create src attribute for iframe
link_col.appendChild(siteVidUrl); // append to DOM

An example of Obj.URL would be

media.website.com/theVideo.mp4

The video contines to autoplay, despite my best attempts. As you can see, I am appending "?autoplay=0", to the end of the src attribute URL, but no luck there. I have read a bit about the video HTML5 tag, but no luck there either...

The majority of the videos are .mp4 files.

Can anyone point me in the right direction?

Upvotes: 1

Views: 5234

Answers (1)

SDwarfs
SDwarfs

Reputation: 3239

Is it necessary to use an iframe for this? If not have look at the HTML5 video-tag: https://www.w3schools.com/htmL/html5_video.asp

If the iframe is needed (for any reason), you could set the src to a page which receives the URL of the video as a parameter and just produces the HTML containing a simple video-tag in it. This way you'll be able to control the video playback and disable autoplay.

Upvotes: 1

Related Questions