Solved

How to use splash image for video?

Posted on 2013-01-05
7
408 Views
Last Modified: 2013-01-07
This is a followup to http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/CSS/Q_27984477.html.    I'd like to embed a youtube video but use a splash image.

Video.js uses uses something like this:

<video id="example_video_1" class="video-js vjs-default-skin" controls width="640" height="264" poster="http://video-js.zencoder.com/oceans-clip.jpg" preload="auto" data-setup="{}">
  <source type="video/mp4" src="http://video-js.zencoder.com/oceans-clip.mp4">
</video>

Open in new window

Youtube uses an iframe.  If you try referencing the iframe video source using the above technique, the video will stall on the loading animation.  Is it possible to hide the iframe so the splash image can display?  Then once the user clicks the splash image, it hides and the iframe displays with the youtube video playing?
0
Comment
Question by:brettr
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:s8web
ID: 38748388
Sure, is jquery already included on the page?
0
 
LVL 16

Expert Comment

by:s8web
ID: 38748395
If so, this should work.
http://jsfiddle.net/pQUqd/
0
 
LVL 16

Expert Comment

by:s8web
ID: 38748403
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			img#splashimage:hover{cursor:pointer}
		</style>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
		<script>
			$(document).ready(function() {
				$('#example_video_1').hide();
				$("#splashimage").click(function() {
					$('#splashimage').hide();
					$('#example_video_1').show();
				});
			});
		</script>
		<title>brettr</title>
	</head>
	<body>
		<video id="example_video_1" class="video-js vjs-default-skin" 
			controls width="640" height="264" poster="http://video-js.zencoder.com/oceans-clip.jpg" 
			preload="auto" data-setup="{}">
			<source type="video/mp4" src="http://video-js.zencoder.com/oceans-clip.mp4">
		</video>
		<img id="splashimage" 
			src="http://www.experts-exchange.com/images/experts-exchange/experts-exchange-logo.png" 
			alt="Some alt content. This shows if the image doesn't" />
	</body>
</html>

Open in new window

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:brettr
ID: 38748634
There are two problems:

1.) The video doesn't play after you click the image.
2.) It doesn't work for youtube videos.

Here's a youtube video link from some embed code if you want to try it: http://www.youtube.com/embed/K-D5HxyV6AU
0
 

Author Comment

by:brettr
ID: 38748669
0
 

Author Comment

by:brettr
ID: 38748715
Unfortunately, the above link only works in FF.  In Safari and Chrome, it begins playing immediately.  Guess the autoplay flag has different behavior in the different browsers.

Is it possible to initially have the iframe url set to null and add the url once the user clicks the image?

Actually, this works in Safari and Chrome but not FF.  Guess I need a conditional:

<div onclick="actualNextSibling(this).style.display='block'; window.frames['youtubeiframe'].document.location.href='http://www.youtube.com/embed/PrKR07ofRRE?rel=0&autoplay=1'; this.style.display='none'">
    <img src="images/Grooming-Twitter-List-Cover.png" alt="splash" style="cursor: pointer" />
</div>
<div style="display: none">
    <iframe id="youtubeiframe" width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>
</div>

Open in new window


--- EDIT ---
Looks like adding name="youtubeiframe" to the iframe tag allows FF to work.  Any idea if assigning the same id and name values will cause issues?
0
 
LVL 16

Accepted Solution

by:
s8web earned 500 total points
ID: 38748818
I missed the autoplay part. You can do it like this:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			#splashimage:hover{cursor:pointer}
		</style>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
		<script>
			$(document).ready(function() {
				$("#splashimage").click(function() {
					$('#splashimage').hide();
					$('#youtubevideo').show();
				});
			});
		</script>
		<title></title>
	</head>
	<body>
		<img id="splashimage" 
			src="http://www.experts-exchange.com/images/experts-exchange/experts-exchange-logo.png" 
			alt="Some alt content. This shows if the image doesn't" />
		<div id="youtubevideo" style="display:none">
			<iframe width="420" height="315" src="http://www.youtube.com/embed/K-D5HxyV6AU?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
		</div>
	</body>
</html>

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question