Solved

How to use splash image for video?

Posted on 2013-01-05
7
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 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