Solved

How to use splash image for video?

Posted on 2013-01-05
7
398 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery, dropdown 4 37
using web browser with BING 40 86
Box Model and Styling 12 20
Need a good Angular tutorial 5 32
This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

758 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

21 Experts available now in Live!

Get 1:1 Help Now