Rephrasing the question
HTML5 video autoplay is not working in slick.js on chrome and safari.
everthing is working fine in firefox.
Autoplay works fine outside the slick container.
I tried this:
Video auto play is not working in Safari and Chrome desktop browser
But cant seem to get it to work.
My slick setup
$(document).ready(function () {
$('.slick-hero').on('init', function (e, slick) {
var $firstAnimatingElements = $('div.slick-hero:first-child').find('[data-animation]');
doAnimations($firstAnimatingElements);
});
$('.slick-hero').on('beforeChange', function (e, slick, currentSlide, nextSlide) {
console.log(nextSlide);
var $animatingElements = $('div.slick-slide[data-slick-index="' + nextSlide + '"]').find('[data-animation]');
console.log($animatingElements.length);
doAnimations($animatingElements);
});
$('.slick-hero').slick({
autoplay: true,
autoplaySpeed: 7000,
pauseOnHover: false,
speed: 1000,
dots: true,
fade: true,
adaptiveHeight: true
});
function doAnimations(elements) {
var animationEndEvents = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
elements.each(function () {
var $this = $(this);
var $animationDelay = $this.data('delay');
var $animationType = $this.data('animation');
$this.css({
'animation-delay': $animationDelay,
'-webkit-animation-delay': $animationDelay
});
$this.addClass($animationType).one(animationEndEvents, function () {
$this.css({});
$this.removeClass($animationType);
});
});
}
});
Original question:
I cant get a simpel HTML5 video to autoplay.
everthing is peachy in Firefox.
My relatively straight forward implementation
<video poster="assets/video/ocean.jpg" id="bgvid" controls autoplay loop muted>
<source src="assets/video/ocean.mp4" type="video/mp4">
<source src="assets/video/ocean.webm" type="video/webm">
<source src="assets/video/ocean.ogv" type="video/ogg">
</video>
This doesn't work!!! the controlls work fine, but autoplay doesn't.
I tried opening it in the browser by double-clicking, via localhost and on a my own website... nothing.
The URL´s to the videos are fine, i tested them.
Im on a macbook pro using latest version of chrome and safari.
Everything works just fine in firefox.
This example works fine:
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_video_autoplay,
This example works fine:
https://codepen.io/dudleystorey/pen/knqyK
Tried using this allso:
https://github.com/VodkaBears/Vide/
The demo files work just fine.
But when i trie to implement it on my own code, then it just shows the poster image.
Re-posting the answer from a related question:
After using jQuery play() or DOM maniupulation as suggested by the other answers, it was not still working (Video wasn't autoplaying) in the Chrome for Android (Version 56.0).
As per this post in developers.google.com, From Chrome 53, the autoplay option is respected by the browser, if the video is muted.
So using autoplay muted attributes in video tag enables the video to be autoplayed in Chrome browsers from version 53.
Expert from the above link:
Muted autoplay for video is supported by Chrome for Android as of version 53. Playback will start automatically for a video element once it comes into view if both autoplay and muted are set[...]
<video autoplay muted>
<source src="video.webm" type="video/webm" />
<source src="video.mp4" type="video/mp4" />
</video>
Muted autoplay is supported by Safari on iOS 10 and later.
Autoplay, whether muted or not, is already supported on Android by Firefox and UC Browser: they do not block any kind of autoplay.
If any of the parents of this video tag in your code have any DOM manipulation on them, autoplay won't work in Safari and Chrome. Here's a similar question with answers that should help you:
Video auto play is not working in Safari and Chrome desktop browser
Related
I have videos on my site that I autoplay using the VideoJS library. The videos are played as muted. The videos autoplay fine on the Safari browser with my iPhone, but do not work on some of my friends' phones (same phone and iOS version as me).
Sorry I don't have a lot of information as I cannot replicate the issue on my device. One clue I have is that I see a big play button on the problematic browsers (first image). I used CSS to style the play button differently (second image).
Any leads would be amazing. Thank you!
Here are my video tag and VideoJS options:
html:
<video
playsinline
muted
>
VideoJS Options:
{
autoplay: true,
controls: false,
loop: true,
muted: true,
preload: 'auto',
};
Did you try with this attr: autoplay, muted and playsinline. Example:
<video autoplay muted loop playsinline>
<source src="video.mp4" type="video/mp4">
</video>
If you're seeing inconsistent behaviour across the same iPhone model and iOS/browser version, one likely explanation is that your friend's phones are on 'low-power mode' or 'low data mode' to preserve battery or bandwidth - these modes are known to disable video autoplay in Safari.
https://developer.apple.com/forums/thread/709821
https://shaktisinghcheema.com/how-to-autoplay-video-on-mobile-devices-on-low-power-mode/
<audio autoplay loop>
<source src="boss.mp3">
</audio>
This is in my game index, and it should work. But when i load up the page I hear nothing, all my other sounds work except this one
Here is my full code https://github.com/Mzema4818/Dragon-Escape/blob/master/index.html
Some browsers block autoplay request due to it's annoying feature by default. I have made it to work using the code below. It works on chrome. It also work on safari only if the user allows to play autoplay from site preferences setting. If you are on safari, go to Safari -> Settings for this website -> "Allow all Auto-Play". I hope it helps.
<audio class="bgmusic" autoplay loop>
<source src="boss.mp3" type="audio/mpeg">
</audio>
<script>
$(document).ready(function() {
$('.bgmusic').on('canplay', function() {
this.play();
});
});
</script>
I had forked your GitHub repository to tweak the scripts. Here's the link to my repo: https://github.com/ashishpatelcs/Dragon-Escape/blob/master/index.html
and a working demo: https://ashishpatelcs.github.io/Dragon-Escape/
Please let me know if there is any issue.
I'm trying to get a video to work with videoJS and with the help of the videoJS guide I got it working on Chrome and Firefox, but not IE8.
I've added the CDN tags to my head and created a videotag.
I'm using the following:
<video id="my_vid" class="video-js vjs-default-skin"
controls preload="auto" width="244px" height="196px"
poster="img/poster.jpg">
<source src="files/mymov.mp4" type='video/mp4' />
<source src="files/mymov.webm" type='video/webm' />
<source src="files/mymov.ogv" type='video/ogg' />
</video>
It seems like the Flash fallback isn't working in IE8, since it doesn't create a flash object when I look in my inspector (which it does at the homepage of videojs.com). The video tag just remains, and IE8 can't cope with that. The video on the homepage of videojs.com is shown properly in IE8.
What am I doing wrong?
Solved: It seems like I had to add data-setup="{}" as an attribute in the video tag. The only problem now is that the video won't play in Chrome.
You can force videJS to display flash. You can use rtmp streaming to use flash
vjs.options.techOrder = ["flash", "html5", "links"];
$(document).ready(function() {
setTimeout(function() {
vjs("videoPlayer").ready(function() {
var swfVideo = $("#videoPlayer_flash_api")[0];
swfVideo.vjs_setProperty("RTMPConnection", "path");
swfVideo.vjs_setProperty("RTMPStream", "videoName");
});
}, 1000);
});
I use this code to make a video (eg. banner, so no controls) autoplay and loop forever.
<video id="video1" class="video-js vjs-default-skin"
controls width="900" height="500"
poster="myposter.jpg"
data-setup='{
"controls": false,
"loop": "true",
"autoplay": true,
"preload": "true"}'>
<source src="thisismyvideoyay.webm" type='video/webm' />
</video>
It works fine on my computer but on my phone (Android OS 4.2.2 with Chrome) it's not autoplaying or preloading and not looping after it finished.
I read this on Video.js page:
Auto: Start loading the video immediately (if the browser agrees). Some
mobile devices like iPhones and iPads will not preload the video in
order to protect their users' bandwidth. This is why the value is
called 'auto' and not something more final like 'true'.
I set the preload to true but it still doesn't autoplay or loop.
Is that a feature of my browser and how can I avoid that?
I tried on other browsers:
UC Browser doesn't seem to support HTML5 at all?
Stock browser shows a little video icon but doesn't show the player, too
↑ Same with Maxthon ↑
To solve the autoplay issue on iOS, do not use the videojs options to autoplay the video.
In other words, this will not work:
<video id="my-video-id" autoplay></video>
Neither will this:
videojs('my-video-id', {
"autoplay": true
});
Instead wait for the video object to load and then trigger the play action:
videojs('my-video-id').ready(function() {
this.play();
});
On a phone, there's no way you can get it to loop or preload data. But I do have a solution where you could autoplay it. You could use my code here = http://www.andy-howard.com/recreate-bbc-iplayer/index.html
And simply add an addition click function on the document ready. This would then make the browser on the phone click the image, which then in turn converts the data tags to video tags, which then converts to the videojs player, which then plays :)
Hope that's helpful.
On mobile, you can autoplay if you put muted option
<video autoplay muted>
<source src="video.webm" type="video/webm" />
<source src="video.mp4" type="video/mp4" />
</video>
Chrome v53: https://developers.google.com/web/updates/2016/07/autoplay
iOS 10 : https://webkit.org/blog/6784/new-video-policies-for-ios
This works for me use this on video tag
data-setup='{ "controls": false, "autoplay": true, "preload": "auto", "loop":true }'
player.ready(function() {
setTimeout(function() {
player.play();
}, 1000);
});
The following HTML code works in Firefox but not in Chrome. In the latter, the play button in non functional.
<video id="mmswf50534a6a5e263" controls="controls" mediagroup="mmswf50534a6a5e263">
<source src="http://video-js.zencoder.com/oceans-clip.webm" type="video/webm">
</video>
Whereas this code works in both browsers.
<video id="mmswf50534a6a5e263" controls="controls">
<source src="http://video-js.zencoder.com/oceans-clip.webm" type="video/webm">
</video>
I have no idea why the mediagroup property affects the play button functionality.
All other control buttons work. I can even right click the video in Chrome and start it.
A Chrome bug? Tested version is: 21.0.1180.89
It looks like you're generating videos in Typo3. I had the same problem and I could not find where it would append the mediagroup.
I solved the problem by adding this script to my base template :
//Remove all mediagroup attributes from video tag
window.onload = function(){
var lstMedia = document.getElementsByTagName("video");
for(var i = 0; i < lstMedia.length; i++) {
if(lstMedia[i].hasAttribute("mediagroup")) {
lstMedia[i].removeAttribute("mediagroup");
}
}
}
Probably not a clean solution, but it worked for me.
Note: I use Typo3 4.7