Solved

How to use splash image for video?

Posted on 2013-01-05
7
401 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
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 …

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now