]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
primary commit
authorAnna Sob <annasob@Anna-Sobs-iMac.local>
Mon, 31 May 2010 17:39:09 +0000 (13:39 -0400)
committerAnna Sob <annasob@Anna-Sobs-iMac.local>
Mon, 31 May 2010 17:39:09 +0000 (13:39 -0400)
images/years.ogv [new file with mode: 0644]
index.html [new file with mode: 0644]
video.js [new file with mode: 0644]

diff --git a/images/years.ogv b/images/years.ogv
new file mode 100644 (file)
index 0000000..766124b
Binary files /dev/null and b/images/years.ogv differ
diff --git a/index.html b/index.html
new file mode 100644 (file)
index 0000000..916459f
--- /dev/null
@@ -0,0 +1,67 @@
+<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> 
+
diff --git a/video.js b/video.js
new file mode 100644 (file)
index 0000000..d29696e
--- /dev/null
+++ b/video.js
@@ -0,0 +1,71 @@
+$(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);
+}
+