--- /dev/null
+<html>
+ <head>
+ <title>html5 video demo</title>
+ <script src="http://code.jquery.com/jquery.js"></script>
+ <script src="http://google.com/jsapi"></script>
+ <script>google.load("language","1");</script>
+ <script src="video.js"></script>
+ <style type="text/css" media="screen">
+ body { background-color:#eee; }
+ #container {
+ width:850px;
+ margin:auto 50px;
+ border:1px solid #ccc;
+ background:white;
+ padding:20px;
+ position:relative;
+ }
+ #sub {
+ position:absolute;
+ top:435px;
+ left:40px;
+ color:white;
+ font-weight:bold;
+ font-family:sans-serif;
+ text-shadow:black 1px 1px 3px;
+ width:820px;
+ font-size:25px;
+ }
+ select { font-size:30px; float:left; }
+ #credit { font-size:25px; color:#999; float:right; padding-top:3px; }
+ #credit a { color:#555; }
+ .clear { clear:both; }
+ </style>
+ </head>
+ <body>
+ <div id="container">
+
+ <video src="images/years.ogv" ontimeupdate="update(this)" controls>
+ <subtitles>
+ <subtitle from="0:02" to="0:05">Intro. Lyrics start at ~0:16</subtitle>
+ <subtitle from="0:16" to="0:22.5">I'm fifteen for a moment, caught in between ten and twenty</subtitle>
+ <subtitle from="0:23" to="0:30">and I'm just dreaming, counting the ways to where you are.</subtitle>
+ <subtitle from="0:32" to="0:39">I'm twenty-two for a moment, and she feels better than ever and we're</subtitle>
+ <subtitle from="0:39" to="0:46.5">on fire, making our way back from Mars.</subtitle>
+ <subtitle from="0:48" to="0:56">Fifteen there's still time for you, time to buy and time to lose.</subtitle>
+ <subtitle from="0:56.5" to="1:08">Fifteen, there's never a wish better than this, when you've only got a hundred years to live</subtitle>
+ </subtitles>
+ </video>
+ <div id="sub" border="2"></div><br/>
+
+ <div id="bottom">
+ <select id="language">
+ <option val="en">English</option>
+ <option val="es">Spanish</option>
+ <option val="fr">French</option>
+ <option val="de">German</option>
+ <option val="ja">Japanese</option>
+
+ </select>
+ <div id="credit">with help from <a href="http://google.com/translate">Google Translate</a> and <a href="http://jquery.com">jQuery</a></div>
+ </div>
+ <div class="clear"></div>
+ </div>
+ </body>
+
+</html>
+
--- /dev/null
+$(function() {
+ $("video").each(function() {
+ if (lang=window.location.search.substring(1)) {
+ var ret=true;
+ $("select option").each(function() {
+ if ($(this).attr("val") == lang) { $(this).attr("selected",true); ret=false; }
+ });
+ if (!ret) {
+ $("subtitle").each(function() {
+ var sub = $(this);
+ google.language.translate($(this).html(),"en",lang, function(r) {
+ sub.html(r.translation);
+ });
+ });
+ }
+ }
+
+ $("#language").change(function() { window.location="?" + $("#language option:selected").attr("val"); });
+ });
+});
+
+var lt = 0;
+function update(vid) {
+ var has_sub=false,
+ t = vid.currentTime;
+ if (lt>t) $("#sub span").fadeTo(1,.3);
+ $("subtitle").each(function() {
+ var from = to_secs($(this).attr("from")),
+ to = to_secs($(this).attr("to"));
+ $(this).removeClass("good");
+ if (from<t&&to>t) {
+ has_sub=true;
+ $(this).addClass("good");
+ }
+ });
+ if (!has_sub) {
+ if (!$("#sub").hasClass("fading"))
+ $("#sub").addClass("fading").stop().animate({ opacity:0, top:"-=30px" }, "medium", "swing");
+ } else {
+ if ($("#sub").hasClass("fading"))
+ $("#sub").removeClass("fading").stop().animate({opacity:1,top:"410px"},1).html('');
+ }
+ $("subtitle.good:last").each(function() {
+ if (!$(this).hasClass("on")) {
+ $("subtitle.on").removeClass("on");
+ $(this).addClass("on");
+ $("#sub").html('').hide();
+ var letters = $(this).text().split('');
+ $.each(letters,function(i, val) {
+ $("#sub").append('<span>' + val + '</span>');
+ });
+ $("#sub span").stop().fadeTo(1,.3, function() { $(this).show(); });
+ }
+ var from = to_secs($(this).attr("from")),
+ to = to_secs($(this).attr("to")),
+ perc = ((t-from)/(to-from)),
+ num_letters = $(this).text().length*perc,
+ i = 0;
+ $("#sub span").each(function() {
+ if (i++>num_letters) return;
+ $(this).stop().fadeTo("fast",1);
+ }).parent().show();
+ });
+ lt = t;
+}
+
+function to_secs(time) {
+ var t = time.split(":");
+ return parseInt(t[0]*60,10) + parseInt(t[1],10);
+}
+