简体   繁体   中英

HTML5 Video not working in iPhone and iPad

I am working on a web app where i need to add video tag which is to be compatible for all devices. I use the below JavaScript code to add video

var src = "some mp4 file source";
var video = document.createElement("video");
video.width = 600;
video.height = 400;
video.controls = true;
video.autoplay = true;
video.preload = "auto";
video.src = src;
element.appendChild(video);

The above code works fine in all browsers which have compatible with HTML5 and in all devices except iPhone and iPad which shows some error occurred.

What am i missing ?

This code will be better if you want to implement a video that will work on any devices

<video width="600" height="400" autoplay>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

Here de documentation that you will need: html5 video

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM