Magnific Popup with html5 video - magnific-popup

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

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');
});
});

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>

Fabric.js - Touch Event Propagation

I have an HTML5 page, and it looks like this:
<html>
<head></head>
<body>
<canvas id="c1" width="500" height="500" />
</body>
</html>
I used Bootstrap 3 and Fabric.js as a canvas library. When I run it on mobile device, I have got an issue that when I touch the object on canvas and move it, the page is moved too. Seems the touch event is also handled by mobile device browser.
What I expect is that to stop the default event handle for mobile device browser, so when I touch the object in canvas and move it, the web page will not move as well. How can I make this with Fabric.js?
I have changed the way while I making the html:
<meta name="viewport" content="width=device-width, initial-scale=0.5, user-scalable=no">
And then, to prevent browser default zoom bouncing, we can bind "touchmove" in document and disable it. That's from jQuery mobile, but vmousemove = touchmove for mobile device somehow.
$(document).on("vmousemove", "body", function(e) {
e.stopPropagation();
e.preventDefault();
return false;
});
This is not about Fabric.js anyway, so I don't have to change Fabric.js or else.

how to open list of video links in JW player 6 (mp4 format / light box)

I have a webpage which opens .flv video files in light box (top_up-min.js/modal). Now i am trying to open the .mp4 version of same video files using JW player 6 in a light box.
The code i tried is working to open a video in lightbox [jquery.jwbox.js ] and suggested code opens a hidden div as a lightbox .But i have below issues
1.After clicking the video ,click anywhere else other than “close button” the video still closes.
In IE 8 or above , even after closing the video ,you can hear the audio. It only stops when you refresh the page .
Does anyone already using this have any fix for this?
2.Is there any other jquery light that can be used for JW player (mp4 format)
Thanks
<head id="Head1" runat="server">
<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript" src="jwplayer/jwplayer.js" ></script>
<script type="text/javascript" src="/js/jquery.jwbox.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jwbox.css" />
<script type="text/javascript">jwplayer.key = "key";</script>
<title></title>
<script type="text/javascript">
//this function i tried to close the video because the existing jquery one
closes video even when u touch outside the box.but its throwing js error.
function fnClose() {
document.getElementById('jwbox_hidden').style.display = 'none';
document.getElementById('jwbox_background').style.display = 'none';
jwplayer().stop(true);
return false;
}
function loadVideo(myFile,title) {
document.getElementById("videoTitle").innerHTML = title;
jwplayer("player").setup({
file: myFile,
width: '640',
height: '480',
volume: 100,
autostart: true,
primary: "flash"
});
}
</script>
</head>
<body>
<p>
Click the link to display a JW player with a video in the JW Box.
</p>
<div class="jwbox">
<ul> <li>Nursery Workers</li></ul>
<ul> <li>Computer Programmers</li></ul>
<ul> <li>Child Care Workers</li></ul>
<div class="jwbox_hidden" id="jwbox_hidden">
<div class="jwbox_content">
<label id="videoTitle" class="te_title"> </label>
<a class="te_close_link" style="display: block;" onclick="fnClose();" ></a>
<div id="player"></div>
</div>
</div>
</div>
<br />
</body>
I know this might not be the answer you're precisely looking for but it worked when I tested it. I haven't found the precise cause of the problem. This is a hacky workaround.
If you look in jwbox.js there's a try catch block like this:
try {
$.jwbox.player.sendEvent("STOP");
$.jwbox.player = null;
} catch (err) { }
I added your fnClose() into the catch block:
try {
$.jwbox.player.sendEvent("STOP");
$.jwbox.player = null;
} catch (err) { fnClose() }
Alternatively, this seems to perform faster:
try {
fnClose();
$.jwbox.player.sendEvent("STOP");
$.jwbox.player = null;
} catch (err) { }
That at least invokes fnClose() when if sendEvent("STOP") fails, which is, I believe, the root of the problem.
Hope that helps, sorry this is my first StackOverflow answer :)
-Pablo

autostart jwplayer html5 for iphone browser

ive this code to run live streaming using jwplayer , its 2 part one if users was using PC and other if user using iphone , setting working fine for pc but when comes to html5 auto start never works , any tips to fix my configuration for html5
PS player working on iphone just when i click play ,
<!DOCTYPE html>
<html>
<head>
<title>live stream!</title>
</head>
<body>
<br />
<br />
<br />
<br />
<br />
<center>
<script type='text/javascript' src='/player/jwplayer.js'></script>
<div id='container'></div>
<script type="text/javascript">
jwplayer('container').setup({
autostart: "true",
file: "http://184.172.184.2:8000/;listen.pls",
height: 300,
width: 600,
players: [
{ type: "flash", src: "player/player.swf", config: {provider: "sound"} },
{ type: "html5", config: {provider: "sound"} }
],
});
</script>
<br />
<br />
<br />
Please click play then wait 10 second for buffer ..... , Thanks
</center>
</body>
</html>
yo can't. but you could detect the ios browser and redirect it to the video itself, causing it to start..
javascript:
function isiPhone(){
return (
(navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPod") != -1) ||
(navigator.platform.indexOf("iPad") != -1)
);
}
if(isiPhone()){
window.location = "path/to/video.mp4";
}
or php:
<?php
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(
strstr($userAgent,'iphone') ||
strstr($userAgent,'ipod') ||
strstr($userAgent,'ipad')
)
{
header ("Location: path/to/video.mp4");
}
?>
Unfortunately, autostart does not work with iPhone's. This is what I gathered on some forums online.
From what I gathered, autostart won't work on iOS devices as media playing needs to be activated via user interaction. This leads to all kind of strange behaviour with playlists, for example -- I'm experiencing inconsistent firing of the "ended" event when playing mp3 files, tested with JWPlayer and pure HTML5 Audio objects.