Play event does not work in HTML and Javascript - onmouseover

I have a problem with my javascript code, maybe you can find what I'm doing wrong. My Play() event does not do what I want.
I want to "re-make" a page of the ferrari site with an onmouseover event. This code is written with a HTML widget inside of elementor, maybe is that the reason why something isn't working.
Hope to hear from you!
My code;
<div class="wrapper1" >
<video id="Hvideo" width="320" height="240" preload="auto">
<source src="https://www.youtube.com/watch?v=HJVHZR3KkjM" type="video/mp4">
</video>
<button id="Htext" onmouseover="Play()" onmouseout="Pause()">HVAC</button>
</div>
<script type="text/javascript">
var Htext=document.getElemenetById("Htext");
var Hvideo=document.getElemenetById("Hvideo");
function Pause(){
Hvideo.pause();
}
function Play(){
if(Hvideo.paused)
Hvideo.play();
}
</script>
image
www.ferrari.com

Related

Video.js - loadedmetadata event never fires

I am having trouble with videojs: when attaching an eventlistener to the "loadedmetadata" event, the callback function is never executed.
The best explanation I found seems to be that some events may fire before Video.js binds the event listeners: Video.js - loadeddata event never fires.
Unfortunately, the solution proposed in this post does not seem to work for me.
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script type="text/javascript">
function init() {
var video = document.getElementById('myVideo');
video.addEventListener("loadedmetadata", function () {
alert("test");
});
}
window.addEventListener("load", init);
</script>
</head>
<body>
<video id='myVideo' class="video-js vjs-default-skin" controls data-setup='{}'>
<source id='mp4' src="http://goo.gl/fAHXgj" type='video/mp4'>
<source id='webm' src="http://goo.gl/03LOHW" type='video/webm'>
</video>
</body>
</html>
When I launch it from Visual Studio (2013), the code above produces an alert pop up only in IE(11); it does not work with Firefox nor Chrome.
When I publish it on my website it never works.
What am I missing? Thank you for reading!
As misterben said, use the .on method. But put it in the ready callback or it will not work:
var player = videojs('myVideo');
player.ready(function(){
this.on('loadedmetadata', function(){ alert('lmd'); })
});
Source: just figured this out myself.
I know misterben has mentioned using the ready callback but you may not have known that you need to use it.
As you're using video.js you need to use it's API, e.g.
videojs('myVideo').on('event',function);
Even better, remove the data-setup attribute and create the player by calling the if to videojs() along with a callback function to be executed as soon as the player is ready:
videojs('myVideo', {}, function(){
this.on('loadedmetadata', function(){
alert('lmd');
});
});

Magnific Popup with html5 video

How to use magnific-popup to retrieve and popup an html5 video from my server instead of getting the video from youtube, vimo, ...?
<video width="500" height="350" controls>
<source src="/static/video/bunny.mp4" type="video/mp4" />
Your browser does not support this video format.
</video>
Thanks.
I have got this to work using the following as a link to open the video:
<a class="popup-player" href="/static/video/bunny.mp4">
video link
</a>
and then used the Iframe type to display it:
$('.popup-player').magnificPopup({
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: false,
fixedContentPos: false,
iframe: {
markup: '<div class="mfp-iframe-scaler">'+
'<div class="mfp-close"></div>'+
'<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
'</div>',
srcAction: 'iframe_src',
}
});
This is a very basic version, it opens the video in an iframe but I have yet to work out how to change the things like the height and width. I'm still learning this stuff so I dont know how it works I just know it puts a video up on the screen. If you get it working and build a more complex version please let me know so I can improve my version.
This worked great for me. Uses "Inline" type with auto-starting HTML5 video.
Javascript:
$('.openVideo').magnificPopup({
type: 'inline',
callbacks: {
open: function() {
$('html').css('margin-right', 0);
// Play video on open:
$(this.content).find('video')[0].play();
},
close: function() {
// Reset video on close:
$(this.content).find('video')[0].load();
}
}
});
HTML:
<a href="#video-01" class="openVideo">
<div id="video-01" class="video-popup mfp-hide">
<video preload="false" poster="/videos/01.png">
<source src="/videos/01.mp4" type="video/mp4">
</video>
</div>
Original source: https://github.com/dimsemenov/Magnific-Popup/issues/626
I think that you should check basics first:
-if the path to plugin is correct and included correctly
<!-- Magnific Popup core CSS file -->
<link rel="stylesheet" href="magnific-popup/magnific-popup.css">
<!-- jQuery 1.7.2+ or Zepto.js 1.0+ -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><br />
<!-- Magnific Popup core JS file --><br />
<script src="magnific-popup/jquery.magnific-popup.js"></script>
It’s not required, but we recommend placing CSS files in <head> and JavaScript files and initialization code in the footer of your site (before the closing </body> tag).
If you already have jquery.js on your site, don’t include it a second time, or use jQuery.noConflict(); mode. Optionally, you can include Zepto.js instead of jQuery, or choose which one to include based on browser support. ACCORDING->http://dimsemenov.com/plugins/magnific-popup/documentation.html
-if you have the movie on your server and if the path to it is correct.
/ is for getting into folder
Then JS:
$(document).ready(function() {
$('.image-link').magnificPopup({type:'image'});
});
For more information see the link I putted few lines above

VideoJS - Executing JS function at end of playback

I'm using VideoJS to play a video on a web page.
I would like, at the end of the video to execute a java script in oder to hide the video DIV and display a other DIV.
Is somebody could help me to do this?
Maximilien
Use the video.js API
videojs('my_video_1').on('ended',function() {
// do something
})
Thank you misterben you solution is working fine.
I did the following to adapt to what I had:
<video id="video"
class="video-js vjs-default-skin vjs-big-play-centered"
controls preload="auto" width="800" height="450"
poster="images/fond.png" data-setup='{}'>
<source src="video/video.mp4" type="video/mp4" />
<source src="video/video.webm" type="video/webm" />
<source src="video/video.ogv" type="video/ogg" />
</video>
<div id="replacingdiv">
<img class="replacingimg" src="./images/invitation.png" alt="Invitation" />
</div>
videojs("video").ready(function() {
var myPlayer = this; // Store the video object
var aspectRatio = 9/16; // Make up an aspect ratio
function resizeVideoJS() {
// Get the parent element's actual width
var width = $(window).width();
if ( width < 800) {
myPlayer.width(width - 10).height( (width -10) * aspectRatio );
$('.replacingimg').width(width - 10).height( (width -10) * aspectRatio);
}
}
myPlayer.on('ended',function() {
$('#video').delay( 2000 ).fadeOut( "slow" , function() {
$('#replacingdiv').fadeIn("slow");
});
});
resizeVideoJS(); // Initialize the function
window.onresize = resizeVideoJS; // Call the function on resize
});
<body>
<div class="vidBox" id="box">
<div class="wrapper">
<div class="videocontent">
<video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="auto" height="auto" poster="posterWTA.png"
data-setup={}>
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
<track kind="subtitles" src="Subtitle.srt" srclang="en" label="01"></track>
<track kind="subtitles" src="Subtitle_2.srt" srclang="en" label="02"></track>
</video>
</div>
</div>
<div id="other" style="display:none; width:400px; height:300px; background-color:#f0f0f0">
This appears after the video ends
</div>
</div>
<script>
var vid=document.getElementById('my_video_1');
vid.addEventListener("ended", hideVideo, false);
function hideVideo() {
var vid=document.getElementById('my_video_1');
var other=document.getElementById('other');
vid.removeEventListener("ended", hideVideo, false);
vid.style.display='none';
other.style.display='block';
}
</script>

videojs Javascript api breaks with flash fallback

I'm using video JS to embed a video, and using a javascript to call a function when the video is done playing.
The problem is that in ie8 and lower, it uses a flash fall back. Is there anyway to get the flash fallback to trigger some sort of 'on video ended' event?
Thanks!
Make sure you're using video.js's API rather than that of an HTML5 video element which may or may not be present. This works:
<video id="MY_VIDEO_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264" poster="http://www.videojs.com/img/poster.jpg">
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
</video>
<script>
//Forcing flash tech
videojs('MY_VIDEO_1',{"techOrder":["flash"]}).ready(function(){
this.on('ended', function(e){
alert('end');
})
});
</script>

Video-JS + Colorbox, loading dynamic videos

Having an issue that has been frustrating me the last few days.
I have some videos on a site that are loaded dynamically from sitecore, and display on a page with thumbnail images. When you click those images you are taken to a lightbox with the video.
The problem is, the video plays in Chrome, Firefox and IE8 -, but not IE9 +. I thought it may be an encoding issue, but I have converted this video so many times to every format available to the web to no avail.
I am setting the plugin to load the video as flash first, then if flash isn't available, load as html5. This will clear all worries in terms of browser support of HTML5 video.
I was thinking that it may be the lightbox and videoJS plugin fighting with each other, or the fact that i am hiding videos and showing them, which i know can sometimes cause issues. I have decided to use a different lightbox, and people seem to have said that colorbox is a decent one to use with videoJS, especially since it has some built in callbacks onLoad.
On to the problem and the code:
The problem:
This lightbox is working, but videoJS seems to throw a few errors when i try and reset the player, which is breaking the videos in IE since its such a dumb browser.
As you can see in the demo link at the bottom, the videos play in IE just fine when they are just set on the page, but when you open the lightbox by pressing "vid1" or "vid2" you are riddled with console errors and the videos no longer play.
The code:
HTML + jScript:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"> </script>
<link href="http://vjs.zencdn.net/4.3/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.3/video.js"></script>
<link type="text/css" rel="stylesheet" href="colorbox.css" />
<script type="text/javascript" src="js/jquery.colorbox.js"></script>
<style type="text/css">
.hide {
display: none;
}
</style>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$(".inline", this).colorbox({
inline: true,
rel: 'videohook',
width: '650px',
onLoad: function() {
//grab the video ID and store it
var vidID = $(this).attr("data-vidID");
//Reset the video players
videojs.players = {};
//set the videoJS player for this video.
videojs(vidID);
}
});
});
</script>
<a rel="videohook" data-vidID="my_video_1" class="inline" href="#video_1">vid 1</a>
<a rel="videohook" data-vidID="my_video_2" class="inline" href="#video_2">vid 2</a>
<div id="video_1" class="video">
<video id="my_video_1" class="video-js vjs-default-skin" controls
preload="none" width="640" height="264" poster=""
data-setup='{"techOrder": ["flash", "html5"]}'>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type='video/mp4'>
<source src="http://www.w3schools.com/html/mov_bbb.ogg" type='video/ogv'>
</video>
</div>
<div id="video_2" class="video">
<video id="my_video_2" class="video-js vjs-default-skin" controls
preload="none" width="640" height="264" poster=""
data-setup='{"techOrder": ["flash", "html5"]}'>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type='video/mp4'>
<source src="http://www.w3schools.com/html/mov_bbb.ogg" type='video/ogv'>
</video>
</div>
</body>
</html>
Console errors im getting:
Uncaught TypeError: Object #<HTMLObjectElement> has no method 'vjs_getProperty'
LIVE DEMO:
Go here to see the errors for yourself: http://kodistro.com
In this case, my solution is to inject the video tag HTML into the lightbox content (when opening) and then call videojs().
So, in pseudo-code:
<script type="text/javascript">
$(document).ready(function() {
$(".inline", this).colorbox({
inline: true,
rel: 'videohook',
width: '650px',
height: '274', //the size most be fixed
onLoad: function() {
var appendVideo1 = '<video id="my_video_1"......> </video>'; //insert the <video> tag. Note.Remove attribute data-setup='{"techOrder": ["flash", "html5"]}'
$("video_1").append(appendVideo1);
},
onComplete: function() {
videojs(my_video_1); //initialize video-js
},
onClosed: function() {
videojs(my_video_1).dispose(); //destroy video-js
}
});
});
</script>
<a rel="videohook" data-vidID="my_video_1" class="inline" href="#video_1">vid 1</a>
<div id="video_1" class="video">
</div>