more or less a complete noob here, so apologies in advance if this question is completely ridiculous!
Effectively I'm building a one page site (artistic purposes) - contained on this site is a video-bg set to autoplay. The autoplay function works fine across all browsers (minus IE) and all devices I've tested thus far.
There's just one issue...
For reasons inexplicable to this noob, autoplay only works when the browsers inbuilt zoom is set to 75% or below. Just to double check this, I trialled embedding the video with 'controls'. Still, the outcome was the same, the video autoplays when the browser zoom is set to 75% or less and it would only play above 75% when prompted ('play' control was clicked) by the user/viewer.
For reasons I can't figure out, autoplay (in my case) is being effected by browser zoom??
I'm working in Muse... Most likely a faux pas??
HTML:
<div class="video-container">
<video autoplay muted loop id="video-bg">
<source src="assets/maskon.mp4" type="video/mp4">
Your browser does not support HTML5 video. Please update to view video content :)
</video>
</div>
CSS:
<style>
#video-bg {
position: relative;
min-width: 100%;
height: 100vh;
}
.video-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
min-height: 100%;
min-width: 100%;
}
</style>
Further apologies for using wrong code insertion function... Code Sample was previewing with about half of code missing??
Your code works in Firefox correctly !
This is probabely one of WebKit's bugs of html5 video
you should use .play() function of javascript to autoplay !
as links below :
Video auto play is not working in Safari and Chrome desktop browser
add this code just after the </video>
<script>
document.getElementById('vid').play();
</script>
UPDATED - TEMPORARY SOLUTION
Thanks to #kaiido I found a temporary solution to this problem.
Inserting the code: window.onresize = function() { requestAnimationFrame(function() { document.getElementById("video-bg").play();})}; after </video> has allowed for functional autoplay capabilites at all zoom resolutions.
Still a bit buggy (page needs to be reloaded every so often) when zooming up/down however, a good for workaround for now :-)
Related
EDIT :
I tested on 12.4.6 Version of iOS, and it plays with no problem.
On my main phone however : iOS 13.3.1 , It still got this problem described here .
I'm kinda new to Angular, and I'm developing an website for a friend, also it helps me to learn.
I ran into this problem. I set a video as a main background and it works fine on computer browsers and Android browsers ( Chrome only tested on android ):
Here's the HTML Code :
<div class="video_box">
<div class="video_overlay"></div>
<video #videoElement [loop]="true" [muted]="true" [volume]="0.2" [autoplay]="true" playsinline id="bgVideo">
<source src="assets/bgVideo.mp4" type="video/mp4"/>
</video>
</div>
Here's the CSS Code :
.video_box {
top: 0;
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
}
.video_box video {
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
position: absolute;
top: 53.5%;
left: 50%;
transform: translate(-50%,-50%);
}
.video_box .video_overlay {
top: 0;
position: absolute;
height: 100%;
z-index:1;
width: 100%;
background: #000000;
opacity: 0.5;
}
It loads fine and most importantly autoplays on Desktop / Android. But on iOS devices when I serve my application and connect to it ( no matter the browser ), it doesn't play, only after user interaction. ( If I click my own Mute or Play buttons )
And by my knowledge it already respects the rules of Safari or Chrome with being muted. ( The volume tag, does not affect it even if I remove it ) .
I tried lifecycle hooks such as ngOnInit or ngAfterViewInit but same story applies .
I ran out of ideas .
Thanks in advance .
I found it. Yes I am also stupid and don't know iOS that better
The thing is, when you have Low Power mode Enabled, the video autoplay in the phone settings is turned OFF and you can't modify that only if you get out of Low Power mode.
I turned that off, and it works as intended.
Thanks. I'll leave this here, maybe others run into it.
I have been building an app recently and have a loading animation playing at the start (just a mp4 video - for aesthetic purposes). It works great everywhere apart from on Iphone.
The issue is that there is a grey line around some of the video - not the same on every side. If i try to screenshot the page the lines are no longer visible.
I am using an iphone 7 plus and ios safari. To see for yourself see - https:pathfinder-new.herokuapp.com
The goal is for it to be seamless with the white background - example can be seen on desktop at above address.
Cheers,
Tim
I’ve been struggling for a few hours and found this as the only way to remove it (tested on Safari, Chrome and Firefox on iOS):
video {
-webkit-mask-image: -webkit-radial-gradient(white, black);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
}
Took inspiration from this gist
I tried that on iOS 12 installed iPad WiFi 2017 on Safari and things were all good. Do you have any chance to video that glitch with another recording device?
Edit: General appearance cleaner -webkit-appearance: none may do the trick.
I had to go with the approach of a wrapper div and a position absolute one, something like:
HTML
<div class="wrapper">
<video loop muted autoplay playsinline>
<source src="./video.mp4" type="video/mp4">
<source src="./video.webm" type="video/webm">
<source src="./video.ogv" type="video/ogg">
</video>
<div class="video-ios-border-fix"></div>
</div>
CSS
.wrapper {
display: block;
position: relative;
font-size: 0;
}
.video-ios-border-fix {
position: absolute;
z-index: 1;
box-sizing: initial;
left: -2px;
top: -2px;
right: -2px;
bottom: -2px;
border: 4px solid #fff;
}
video {
width: 100%;
}
I'm needing to play like 6 videos as background in differents divs at the same time, but in IOS and ANDROID platforms. I'm developing an ionic app.
I've found a solution that works perfectly with web, but when I builded it up, it worked as I supposed: every video that I used as background just play as full screen.
Here goes some code:
.bg-vid {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: 100%;;
z-index: -100;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background: url(http://www.w3schools.com/tags/movie.mp4) no-repeat;
background-size: cover;
}
<div>
<video autoplay muted loop class="bg-vid">
<source src="http://www.w3schools.com/tags/movie.mp4" type="video/webm">
<source src="http://www.w3schools.com/tags/movie.mp4" type="video/mp4">
</video>
</div>
Hope someone can help me.
So for this issue as used 2 things.
First one, on config.xml added the next line
<preference name="AllowInlineMediaPlayback" value="true"/>
And after add the webkit-playsinline directive inside the video tag like this:
<video controls preload="auto" webkit-playsinline><source src="videos/video_file.mp4"></video>
And it works like a charm.
Please note that the above answer is correct, except for the fact that with recent iOS updates to the video tag, the video must also have the muted property set to true in order to allow autoplay without user gesture.
<video controls preload="auto" autoplay playsinline muted loop><source src="videos/video_file.mp4"></video>
I spent all of last night trying to figure this one out, and I hope that this helps someone else out there.
I used this solution to use an html5 video as the background of my site.
However, it doesn't seem to work on iPad/iphone, all I am getting is a black screen, and the video is not resizing.
Also, the video does not resize correctly when the aspect ratio of the window is not the same as the aspect ratio of the video. You will see that the background image begins to become visible.
Thanks!
In http://www.develooping.com/canvas-video-player/ you can see a responsive mp4 background working in iPad/iPhones. Download the code from http://www.develooping.com/wp-content/uploads/2016/04/html-canvas-video-player.zip. It uses an adapted version of HTML canvas video player script by Stanko;
<div class="video-responsive">
<video class="video" muted="muted" loop="loop" autoplay="autoplay">
<source src="mY_movie.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<canvas class="canvas"></canvas>
<div id="over_video">Look at me</div>
</div>
The script is used as follows
<script src="canvas-video-player.js"></script>
<script>
var isIOS = /iPad|iPhone|iPod/.test(navigator.platform);
if (isIOS) {
var canvasVideo = new CanvasVideoPlayer({
videoSelector: '.video',
canvasSelector: '.canvas',
timelineSelector: false,
autoplay: true,
makeLoop: true,
pauseOnClick: false,
audio: false
});
}else {
// Use HTML5 video
document.querySelectorAll('.canvas')[0].style.display = 'none';
}
</script>
The CSS is
body {
background: #000;
padding:0;
margin:0;
}
.video-responsive {
padding-bottom: 56.25%;
position: relative;
width: 100%;
}
.canvas,
.video {
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
background: #000;
z-index: 5;
}
#over_video{
position: absolute;
width: 100%;
height: 100%;
text-align: center;
top: 0;
z-index: 10;
font-size: 12vw;
color: #FFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-top: 20%;
text-shadow: 4px 4px 4px #5C433B;
}
Hope it can help.
Just mark as record.
Nowadays, the ability of background video get supported (iOS 10 +) due to the new policies of WebKit.
To be specific, check out the official document below.
https://webkit.org/blog/6784/new-video-policies-for-ios/
Since iOS10 there is a solution, see here: https://webkit.org/blog/6784/new-video-policies-for-ios/
On iPhone, <video playsinline> elements will now be allowed to play inline, and will not automatically enter fullscreen mode when playback begins.
<video> elements without playsinline attributes will continue to require fullscreen mode for playback on iPhone.
When exiting fullscreen with a pinch gesture, <video> elements without playsinline will continue to play inline.
Unfortunately, the iPad doesn't support automatic video play, so you'd need a play/stop/pause button. Here's an example of something that does work on iPad: http://html5-fullscreen-video.ceseros.de/html_5_fullscreen/movie/1
SquareSpace uses an interesting approach to "simulating" video on their website by using a clever loop of .pngs and overlays. See http://www.squarespace.com/
If you sift through the HTML you will find the hand sequence here: http://cf.squarespace.com/details/musician-hand-sequence-hires.png
It works on phones.. Just something to think about.
The only way to autoplay videos on mobile devices is to ditch the html video tag.
I see three options, assuming you don't need audio:
Use a gif instead of the video. Depending of the animation, the file size will skyrocket though
Use a really long jpg or png that contains every frame of the video and then shift through them with javascript
Decode the video with javascript. For example use this h.264 decoder and play videos with good compression. Only downside I see is that it requires quite some CPU for the decoding.
I went for the last solution and it works fine.
I have stumbled upon something that might help you with this task..
http://vagnervjs.github.io/frame-player/
Its a JS player that receives a JSON list of images representing frames of the video.
This will also provide flexibility with regards to styling options of the video itself and responsiveness..
You could load a different set of images (lower in quality) to suuport IPADs vs. desktop support for instance.
Most easiest way I think, just use gif for background. For example you can convert it online like in http://ezgif.com/video-to-gif
What I want is for example:
<video> = z-index: -1;
<div id="post"> = z-index: 0;
I've tried this to a certain degree... but it would be good to know if anyone has some concrete information on it. I'm new to H5 Video, and I know with Flash it is possible, but not for mobile devices (which I don't care about atm, can have some crappy fallback)
Thanks for any info in advance.
You can stack elements on top of html5 video using z-index, exactly as you described. You can see my demo with this jsfiddle, http://jsfiddle.net/cJJwj/3/
And here's the code that I use in that fiddle:
HTML
<video width="200" height="200"
controls="controls"
src="http://upload.wikimedia.org/wikipedia/commons/4/43/Eisbach_surfen_v1.ogv">
</video>
<p>paragraph</p>
CSS
video {
position: relative;
z-index: 0;
}
p {
position: absolute;
top: 50px;
left: 50px;
color: red;
font-size: 2em;
border: medium solid yellow;
z-index: 1;
}
I should mention, however, that I tried using z-index: -1; for the video, and the video controls wouldn't work (in Firefox 5 beta and Chrome), but when I used z-index: 0 instead, the controls worked fine. I don't know why that is yet.
I haven’t worked with HTML5 video much either, but I know that the Vimeo HTML5 player seems to do exactly what you’re asking. They use <div> and even <canvas> above the video to render the playback controls, title, and other buttons.