Playing a mp4 video using Iframe disable autoplay on google chrome - html

I'm having an issue with Iframe autoplay="0" on Google Chrome.
I have tried every thread and and forum and nothing has worked.
I need the video to pause as soon as the page loads. I cannot use the <video> </video> tag because I need information to pull from a separate library into a main video div.
I haven't found any JavaScript that works and autostart="0" , autostart="false" autoplay="0" , autoplay="false" doesnt work either.
Link : Aza TV
<script>
$(".video-1, .video-2, .video-3").on("click", function(event) {
event.preventDefault();
$(".video_case iframe").prop("src", $(event.currentTarget).attr("href"));
});
</script>
.video_wrapper { width:67%; padding:10px; box-sizing:border-box; float:left; min-height:50px;border: thin solid #F60; border-radius:5px 5px;}
.nextvideo_wrapper { width:31%; padding:8px; box-sizing:border-box; float:left; min-height:400px;border: thin solid #F60; border-radius:5px 5px;margin-left:10px; background:#333;}
<div class="video_wrapper">
<iframe name="someFrame" id="someFrame" width="100%" height="420" src="http://41.76.210.2/vod/azamusica_VictoriaKimani_webisode22_20151022_HDO.mp4?autoplay=0" controls ></iframe>
</div>
<div class="nextvideo_wrapper">
<iframe src="libraries/azamuzika.php" width="100%" height="400px" bg=ffffff&text=000000" frameborder="0"></iframe>
</div>

Please note your selector does not actually match the html you posted.
To keep it simple try to add &autoplay=0 to your urls - if that does not work, try this - I gave the actual iframe an ID of iFrame1 and write the video tag into it
var vid = '<video controls="controls"><source src="__VIDEO__" type="video/mp4" /><!--[if gt IE 6]><object width="640" height="375" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"><! [endif]--><!--[if !IE]><!--><object width="640" height="375" type="video/quicktime" data="__VIDEO__.mp4"><!--<![endif]--><param name="src" value="__VIDEO__" /><param name="autoplay" value="false" /></object></video>';
$(".video-1, .video-2, .video-3").on("click", function(event) {
event.preventDefault();
var ifrm = $('#iFrame1').get(0); // get the DOM object
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm.document.write(vid.replace(/__VIDEO__/g,$(event.currentTarget).attr("href"));
ifrm.document.close();
});

I've tried all the possible solutions but nothing worked for local video bindings. I believe best solution would be to fix using jQuery.
$(document).ready(function () {
var ownVideos = $("iframe");
$.each(ownVideos, function (i, video) {
var frameContent = $(video).contents().find('body').html();
if (frameContent) {
$(video).contents().find('body').html(frameContent.replace("autoplay", ""));
}
});
});
Note: It'll find all the iframes on document ready and loop through each iframe contents and replace/remove autoplay attribute. This solution can be use anywhere in your project. If you would like to do for specific element then use the code under $.each function and replace $(video) with your iframe element id like $("#myIFrameId").

Related

Muting an embedded vimeo video

On a website I am building I have a vimeo video embedded. The client needs to keep the sound on the video obviously for people that find it on vimeo. However for her website the sound is just plain annoying. So I need to find a way to mute the audio within the code for the embed. I have googled it but can't seem to find anything legible. As you can see from my code below, I have used the autoplay command within the link I was hoping I could do a similar thing to mute the sound.
<iframe src="http://player.vimeo.com/video/4415083? title=0&byline=0&portrait=0&color=d01e2f&autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
Thanks
In case it helps anyone, Vimeo have added a 'background' parameter for embedding videos, that autoplays videos silently. In some cases that will be useful where people want to mute videos - this is their example:
<iframe src="https://player.vimeo.com/video/76979871?background=1"
width="500" height="281" frameborder="0" webkitallowfullscreen
mozallowfullscreen allowfullscreen></iframe>
For non-paying members
You just need to add the muted parameter. E.g.:
<iframe src="https://vimeo.com/48400332?autoplay=1&loop=1&muted=1" ></iframe>
For paid members
According to Vimeo, the background parameter is only supported for videos hosted by paid members.
Source: https://help.vimeo.com/hc/en-us/articles/115004485728-Autoplaying-and-looping-embedded-videos
you will be using setVolume api in your vimeo.. player.api('setVolume', 0);
it will be like this...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//f.vimeocdn.com/js/froogaloop2.min.js"></script>
<iframe id="vimeo_player" src="http://player.vimeo.com/video/4415083?title=0&byline=0&portrait=0&color=d01e2f&autoplay=1&player_id=vimeo_player" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<script>
var iframe = $('#vimeo_player')[0],
player = $f(iframe),
status = $('.status');
player.addEvent('ready', function() {
player.api('setVolume', 0);
});
</script>
I tried the examples in the answers with no luck. After looking into the documentation I noticed there is missing the parameter &player_id=IFRAME_ID. Maybe something changed in the Vimeo API, anyway the following example works for me:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>
<iframe id="vimeo_player" src="//player.vimeo.com/video/4415083?api=1&player_id=vimeo_player&autoplay=1&loop=1&color=ffffff" width="1920" height="1080" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<script>
$(function() {
var vimeo_iframe = $('#vimeo_player')[0];
var player = $f(vimeo_iframe);
player.addEvent('ready', function() {
player.api('setVolume', 0);
});
});
</script>
Seems like Vimeo is providing an updated library, and the API syntax is a bit different from the old one (Froogaloop). Here's how to mute an embedded video with JS:
<!--Add the id attr to the iframe tag to use as a selector-->
<iframe id="embeddedVideo" src="http://player.vimeo.com/video/4415083? title=0&byline=0&portrait=0&color=d01e2f&autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<!--Include the Vimeo API Library-->
<script src="https://player.vimeo.com/api/player.js"></script>
<!--Select and manipulate your video-->
<script type="text/javascript">
//Select the #embeddedVideo element
var video = document.getElementById('embeddedVideo');
//Create a new Vimeo.Player object
var player = new Vimeo.Player(video);
//When the player is ready, set the volume to 0
player.ready().then(function() {
player.setVolume(0);
});
</script>
Hope this helps out anyone who's using the new library. Documentation is at vimeo/player.js
Since most of the answers here are referring to Vimeo's old api. Here is the simplest way with the new api. You can include vimeo player.js from their CDN or you can download it or you can include it from npm.
<script src="https://player.vimeo.com/api/player.js"></script>
or
npm install #vimeo/player
then you can do the following.
<script>
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.setVolume(0);
</script>
that's it. And if you are using angular 2+,
import * as Vimeo from '#vimeo/player';
const iframe = e.target;
const player = new Vimeo(iframe);
player.setVolume(0);
here e.target is $event which would be passed from the template. Probably it could be iframe (load) event. Or may be you can use jquery to select iframe.
#Gadss answer works great but I found that you need update the iframe src to include the activation of the Vimeo api. Just include api=1 after the vimeo id.
I've also found that this sometimes doens't work on Safari for some reason.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//f.vimeocdn.com/js/froogaloop2.min.js"></script>
<iframe id="vimeo_player" src="http://player.vimeo.com/video/4415083?api=1&title=0&byline=0&portrait=0&color=d01e2f&autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<script>
var iframe = $('#vimeo_player')[0],
player = $f(iframe),
status = $('.status');
player.addEvent('ready', function() {
player.api('setVolume', 0);
});
</script>
**Here is my solution:
http://jsfiddle.net/jakeoblivion/phytdt9L/5/
(You will need your own play/pause mute/unmute icons)
//load video muted
var video = $("#myvideo");
video.vimeo("play");
video.vimeo("setVolume", 0);
//toggle play/pause
$('#play-pause').click(function() {
$(this).toggleClass('play');
if ($(this).hasClass('play')) {
//pause video
video.vimeo("pause");
$(this).css('background', 'pink');
} else {
//unpause video
video.vimeo("play");
$(this).css('background', 'blue');
}
});
//toggle mute/unmute
$('#mute-unmute').click(function() {
$(this).toggleClass('mute');
if ($(this).hasClass('mute')) {
//unmute video
video.vimeo("setVolume", 1);
$(this).css('background', 'green');
} else {
//mute video
video.vimeo("setVolume", 0);
$(this).css('background', 'red');
}
});
Spent ages trying and nothing seemed to work to.
I just wanted to have a Vimeo autoplay muted (volume 0) with simple Play/Pause Mute/Unmute controls, instead of their default ones. (feel free to use icons instead of the temporary colours I put).
(if you want to add the default controls back but keep muted, remove "?background=1". By default background=1 will set video.vimeo("setVolume", 0) and hide controls, so I also added the mute on load without the background=1 set).
Also note:
"You’ll need to be running on a web server instead of opening the file directly in your browser. JS security restrictions will prevent the API from working when run locally."
I've found a way to do it. You start the video muted so it autoplays, then on the first timeupdate you set the volume to 1.
var options = {
id: 'video_id_here',
width: 640,
loop: false,
muted: true,
autoplay: true
};
var player = new Vimeo.Player('vimeo', options);
player.setVolume(0);
player.on('timeupdate', set_autoplay_volume );
function set_autoplay_volume(){
player.setVolume(1);
player.off('timeupdate', set_autoplay_volume );
}
You try insert ?muted=1 after link in attribute src
For example
<iframe id="vimeo_player" src="https://player.vimeo.com/video/257992348?muted=1">
This is the only way it worked for me: http://jsfiddle.net/87dsjL8q/108/
var iframe = document.getElementsByTagName('iframe')[0];
var player = $f( iframe );
player.addEvent('ready', function() {
player.api('setVolume', 20);
});
<iframe src="http://player.vimeo.com/video/4415083?muted=1; title=0;byline=0;portrait=0;color=d01e2f;autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
you can just give "muted=1" so the video will be muted...
chrome allow the videos autoplay that are muted

how to run js code when video is fully buffered/loaded

I have searched all over google for this and nothing does what it is supposed to
It works perfect in IE ... You can see it in the logs that it works perferct ... But it wont work in chrome!!!
Why is it doing so in chrome ? ... It loads 10sek from catche and then nothing ...
<div style=" width:100%; height:320px; margin-top:-95px; background-image:url('video-logo.png'); background-repeat:no-repeat; background-position:center;">
<div id="videoRain" class="videoWrapper" style="text-align:center; display: none;">
<video id="rainVideo" width="100%" height="400px" preload="auto">
<source src="rain-video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</div>
<script>
setTimeout(function(){
var refreshId = window.setInterval(function(){
myVid=document.getElementById('rainVideo');
puhvitud = Math.round(myVid.buffered.end(0));
if (puhvitud >= 14) {
setTimeout(function(){document.getElementById('videoRain').style.display='block';},0);
setTimeout(function(){document.getElementById('rainVideo').play();},0);
clearInterval(refreshId);
setTimeout(function(){document.getElementById('videoRain').style.display='none';},15000);
}
console.log(puhvitud);
}, 2000);
},1000);
</script>
Maybe someone has another way to do this ?
When the video is fully loaded ... this should be ran...
setTimeout(function(){document.getElementById('videoRain').style.display='block';},0);
setTimeout(function(){document.getElementById('rainVideo').play();},0);
setTimeout(function(){document.getElementById('videoRain').style.display='none';},15000);
EDIT:
Tried this:
<script>
function runVideoRain(){
rainVideo.addEventListener("loadeddata", runRain, false);
}
function runRain()
{
setTimeout(function() {document.getElementById('videoRain').style.display='block';},0);
setTimeout(function(){document.getElementById('rainVideo').play();},0);
setTimeout(function() {document.getElementById('videoRain').style.display='none';},15000);
}, false);
</script>
Does not work !!
Uncaught SyntaxError: Unexpected token ,
Uncaught ReferenceError: runVideoRain is not defined
onloadeddata
You can use the onloadeddata attribute.
onloadeddata : Script to be run when media data is loaded
<video id="rainVideo" width="100%" height="400px" preload="auto" onloadeddata="runMyFunction();">
<source src="rain-video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<script>
function runMyFunction(){
alert('The video is loaded');
}
</script>
It seems that onloadeddata attribute does not work on chrome. But attaching an event handler through addEventListener does the trick !
rainVideo.addEventListener("loadeddata", myRunFunction, false);
//with jQuery
$(rainVideo).on("loadeddata", myRunFunction);

embed youtube html5 player shows no fullscreen button

I include the YouTube player as follows in my php file but the player does not show the fullscreen button. Switching to the flash player works (whether through changing the url from /embed to /v or by disabling &html5=1). What am I doing wrong?
An example is available here: http://jonnyrimkus.square7.ch/stuff/youtube_html5_fullscreen.php
<script>
var tag = document.createElement(\'script\');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName(\'script\')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady() {
player = new YT.Player(\'player\', {
playerVars: {
\'allowfullscreen\': \'true\',
\'allowscriptaccess\': \'always\'
},
events: {
\'onReady\': onYouTubePlayerReady,
\'onStateChange\': playerStateChange,
\'onError\': playerStateError
}
});
}
</script>
<iframe id="player" width="425" height="356" border="0" frameborder="0" src="http://www.youtube.com/embed/36XdO9Iv9ew?enablejsapi=1&playerapiid=lastfmplayer&autoplay=1&html5=1&fs=1&origin=http://jonnyrimkus.square7.ch"></iframe>
The fullscreen button will also not be visible if the Youtube player is inside another iframe that does not have allowfullscreen attribute.
Unlike what Google's documentation says(as of 11/2014), the fs attribute in querystring does not seem to influence the visibility of fullscreen. The visibility seems to be influenced by allowfullscreen attribute in iframe which youtube player puts by default during instantiation. That said, if your embed the player inside another iframe you should also mark that iframe for allowfullscreen ( or all its variants webkitallowfullscreen mozallowfullscreen)
<iframe src='' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen>
<!-- YT player-->
</iframe>
The way you are using the iframe api now does nothing, the api is made to bind on an empty element, like <div id="player"></div>, the id is the first argument in the new YT.Player function.
In order to load a youtube video with the iframe api you need this in the body:
<div id="player"></div>
<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: 480,
width: 640,
videoId: "36XdO9Iv9ew",
});
}
</script>
There is no need to explicitely specify you want to enable fullscreen when using the iframe api.
You can also just use the iframe without the api, you'll need to specify you want fullscreen when you use it.
<iframe width="640" height="480" frameborder="0" id="player" allowfullscreen="1" title="YouTube video player" src="http://www.youtube.com/embed/36XdO9Iv9ew?enablejsapi=1"></iframe>
Just using the iframe tag is a bit faster, but if you want to use the extra features of the iframe api you have no choice.
A page with examples (also check the source): http://qnet.co/yt
You can also implement the fullscreen feature yourself (not needed for Youtube, but still cool):
var goFullscreen = function(id) {
var el = document.getElementById(id);
if (el.requestFullScreen) {
el.requestFullScreen();
} else if (el.mozRequestFullScreen) {
el.mozRequestFullScreen();
} else if (el.webkitRequestFullScreen) {
el.webkitRequestFullScreen();
}
}
var leaveFullscreen = function() {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
and to make the Youtube player go fullscreen with: goFullscreen('player'), and leave fullscreen with: leaveFullscreen()
The different versions of requestFullscreen and cancelFullscreen are for different browsers, because the standard is not yet completely finished
More info on Javascript Fullscreen: http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/ (relative old document, but still valid)
off-topic: It is useless to echo such a string with php, you can just paste it in the body the file outside of the php tags.
This is still an issue in July 2014, and you just wonder if Google will ever fix this. Actually you can force the Flash player in another way at the client end by using a UA Spoofer, and for Google Chrome browser for instance, Chrome Web Store - djflhoibgkdhkhhcedjiklpkjnoahfmg and then spoof a browser that doesn't understand HTML5.
Actually HTML5 video is still a disaster, and the grainey spikey-jaggy edges to the video and the herringbone patterning though faint is still distracting. Whereas Flash is Smooth, Flawless, Reliable, and Sharp edges with zero patterning artifacts.
HTML5 - still big thumbs down, I wouldn't inflict it on users.
Oh yes and still Fullscreen not appear in embeds like this
Rick Astley - Never Gonna Give You Up # viewpure embed
http://viewpure.com/dQw4w9WgXcQ
You can use the above example to fiddle and diddle with different browser plugins.

loop html5 video using ended event broken

I am searching for the holy grail of a simple looping html5 video, I am currently using the following code which doesn't seem work
<video width="650" height="650" class="outer_shadow" autoplay="" ended="this.play()" loop>
<source src="/videos?video_id=ag1kZXZ-anQtd2luZG93cg4LEghUaW1lRGF0YRgNDA">
</video>
Can anyone could hilight why this code doesn't work/suggest their best work arround?
Surely you just need to set the loop attribute (see fiddle tested in Chrome):
<video id="myVideo" width="650" height="650" class="outer_shadow" autoplay loop>
<source src="http://content.bitsontherun.com/videos/nPripu9l-60830.mp4">
</video>​
If firefox still doesn't like the loop attribute, try the following fix:
document.getElementById('myVideo').addEventListener('ended', function(){
this.currentTime = 0;
}, false);
Update:
Perhaps not as simple as you had hoped but, as a work around for the problem, it might be worth trying one of the many HTML5 video libraries such as video.js. If the problem persists you could, as a worst case, force the library to use Flash where supported (ie. desktop) and fall-back to HTML5 where it's not (as explained here).
Here is the fiddle with working example of HTML5 video player that loops several videos. Just add your URLs to src array...
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<video id="video" width="500" height="400" controls autoplay></video>
<script>
var src = [
"http://content.adfox.ru/131007/adfox/205544/865991_11.mp4",
"http://all.rutube.ru/130627/gpmdigital/217059/805529_11.mp4"
];
var curSrc = 0;
$(function() {
$('#video').attr("src", src[curSrc % src.length]);
curSrc++;
var video = $('#video').get(0);
$('#video')
.on('loadedmetadata', function() {
video.currentTime=0.01;
video.play();
})
.on('ended', function() {
console.log('ended');
video.src = src[curSrc % src.length];
video.load();
curSrc++;
});
});
</script>

Getting an Embedded YouTube Video to Auto Play and Loop

I am trying to get a basic Youtube video to auto play and auto loop embedded on a page, but I'm having no luck.
<div style="text-align: center; margin: auto"><object type="application/x-shockwave-flash" style="width:1120px; height:630px;" data="http://www.youtube.com/v/GRonxog5mbw?rel=0&loop=1&autoplay=1&showsearch=0&version=3&showinfo=0&modestbranding=1&fs=1">
<param name="movie" value="http://www.youtube.com/v/GRonxog5mbw?rel=0&loop=1&autoplay=1&showsearch=0&version=3&showinfo=0&modestbranding=1&fs=1" />
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
</object></div>
YouTubes HTML5 embed code:
<iframe width="560" height="315" src="http://www.youtube.com/embed/GRonxog5mbw?autoplay=1&loop=1&playlist=GRonxog5mbw" frameborder="0" allowfullscreen></iframe>​
You can read about it here: Link View original content on the Internet Archive project.
Here is the full list of YouTube embedded player parameters.
Relevant info:
autoplay (supported players: AS3, AS2, HTML5) Values: 0 or 1. Default
is 0. Sets whether or not the initial video will autoplay when the
player loads.
loop (supported players: AS3, HTML5) Values: 0 or 1. Default is 0. In
the case of a single video player, a setting of 1 will cause the
player to play the initial video again and again. In the case of a
playlist player (or custom player), the player will play the entire
playlist and then start again at the first video.
Note: This parameter has limited support in the AS3 player and in
IFrame embeds, which could load either the AS3 or HTML5 player.
Currently, the loop parameter only works in the AS3 player when used
in conjunction with the playlist parameter. To loop a single video,
set the loop parameter value to 1 and set the playlist parameter value
to the same video ID already specified in the Player API URL:
http://www.youtube.com/v/VIDEO_ID?version=3&loop=1&playlist=VIDEO_ID
Use the URL above in your embed code (append other parameters too).
All of the answers didn't work for me, I checked the playlist URL and seen that playlist parameter changed to list! So it should be:
&loop=1&list=PLvNxGp1V1dOwpDBl7L3AJIlkKYdNDKUEs
So here is the full code I use make a clean, looping, autoplay video:
<iframe width="100%" height="425" src="https://www.youtube.com/embed/MavEpJETfgI?autoplay=1&showinfo=0&loop=1&list=PLvNxGp1V1dOwpDBl7L3AJIlkKYdNDKUEs&rel=0" frameborder="0" allowfullscreen></iframe>
Had same experience, however what did the magic for me is not to change embed to v.
So the code will look like this...
<iframe width="560" height="315" src="https://www.youtube.com/embed/cTYuscQu-Og?Version=3&loop=1&playlist=cTYuscQu-Og" frameborder="0" allowfullscreen></iframe>
Hope it helps...
Playlist hack didn't work for me either. Working workaround for September 2018 (bonus: set width and height by CSS for #yt-wrap instead of hard-coding it in JS):
<div id="yt-wrap">
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="ytplayer"></div>
</div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
width: '100%',
height: '100%',
videoId: 'VIDEO_ID',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
player.mute(); // comment out if you don't want the auto played video muted
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
player.seekTo(0);
player.playVideo();
}
}
function stopVideo() {
player.stopVideo();
}
</script>