Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use splash image for video?

Posted on 2013-01-05
7
Medium Priority
?
425 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 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