player/js/player.js
changeset 19 a07c2128b7c1
parent 17 150ccacec493
parent 18 b8a45e2fd6fd
child 20 8c14a340a221
equal deleted inserted replaced
17:150ccacec493 19:a07c2128b7c1
    14     
    14     
    15     IriSP.htmlPlayer(
    15     IriSP.htmlPlayer(
    16         myMedia,
    16         myMedia,
    17         $(".video-container"),
    17         $(".video-container"),
    18         {
    18         {
    19             width: 1000,
       
    20             height: 560,
       
    21             autostart: true,
    19             autostart: true,
    22             url_transform: function(src) {
    20             url_transform: function(src) {
    23                 return [{
    21                 return [{
    24                     type: "video/mp4",
    22                     type: "video/mp4",
    25                     src: src.replace(/\.[\d\w]+$/,'.mp4')
    23                     src: src.replace(/\.[\d\w]+$/,'.mp4')
    30             }
    28             }
    31         }
    29         }
    32     );
    30     );
    33     
    31     
    34     myMedia.on("timeupdate", function(t) {
    32     myMedia.on("timeupdate", function(t) {
    35         var progress = $(".progress-indicator"),
    33         var pos = $(".chapters-bar").width() * t / myMedia.duration;
    36             pos = ($(".chapters-bar").width() - 2 * progress.width()) * t / myMedia.duration;
    34         $(".progress-indicator").css("left",pos);
    37         progress.css("left",pos);
    35         $(".elapsed").css("width", pos);
    38     });
    36     });
    39     myMedia.on("play", function() {
    37     myMedia.on("play", function() {
    40         $(".play-button").addClass("pause");
    38         $(".play-button").addClass("pause");
    41     });
    39     });
    42     myMedia.on("pause", function() {
    40     myMedia.on("pause", function() {
    43         $(".play-button").removeClass("pause");
    41         $(".play-button").removeClass("pause");
    44     });
    42     });
    45     
    43     
       
    44     function showAtMousePos(evt) {
       
    45         var pos = evt.pageX - $(".timeline").offset().left;
       
    46         $(".mouse-progress-indicator").css("left", pos);
       
    47         return pos;
       
    48     }
       
    49     
       
    50     $(".timeline").mouseenter(function(e) {
       
    51         $(".mouse-progress-indicator").show();
       
    52         showAtMousePos(e);
       
    53     }).mouseleave(function(e) {
       
    54         $(".mouse-progress-indicator").hide();
       
    55     }).mousemove(showAtMousePos)
       
    56     .click(function(e) {
       
    57         myMedia.setCurrentTime( showAtMousePos(e) * myMedia.duration / $(".timeline").width());
       
    58     });
       
    59     
    46     var tags = myProject.getTags().sortBy(function(t) {
    60     var tags = myProject.getTags().sortBy(function(t) {
    47             return - t.getRelated("annotation").length;
    61             return - t.getRelated("annotation").length;
    48         }).slice(0,12),
    62         }).slice(0,20).sortBy(function(t) {
       
    63             return t.title;
       
    64         }),
    49         tagTemplate = _.template('<li data-tag-id="<%- id %>" class="tag"><%- title %></li>'),
    65         tagTemplate = _.template('<li data-tag-id="<%- id %>" class="tag"><%- title %></li>'),
    50         clickedTag = null,
    66         clickedTag = null,
    51         lastTag = null;
    67         lastTag = null;
    52     
    68     
    53     $(".tags-list").html(tags.map(tagTemplate).join(""));
    69     $(".tags-list").html(tags.map(tagTemplate).join(""));
    54     
    70     
    55     $(".tags-title").mouseenter(function() {
    71     $(".tags-title").mouseenter(function() {
    56         $(".tags-list").stop().slideDown();
    72         $(".tags-list").stop().slideDown();
    57     });
    73     }).click(function() {
    58     $(".tags").mouseleave(function() {
       
    59         $(".tags-list").stop().slideUp();
       
    60     });
       
    61     
       
    62     $("body").click(function() {
       
    63         if (clickedTag) {
    74         if (clickedTag) {
    64             $(".found").removeClass("found");
    75             $(".found").removeClass("found");
    65             clickedTag = null;
    76             clickedTag = null;
    66         }
    77         }
    67         return false;
    78         return false;
       
    79     });
       
    80     $(".tags").mouseleave(function() {
       
    81         $(".tags-list").stop().slideUp();
    68     });
    82     });
    69     
    83     
    70     function showTag(tagId) {
    84     function showTag(tagId) {
    71         $(".found").removeClass("found");
    85         $(".found").removeClass("found");
    72         var tag = myProject.getElement(tagId);
    86         var tag = myProject.getElement(tagId);
    82     $(".tag").hover(function() {
    96     $(".tag").hover(function() {
    83         showTag($(this).attr("data-tag-id"));
    97         showTag($(this).attr("data-tag-id"));
    84     }, function() {
    98     }, function() {
    85         showTag(clickedTag);
    99         showTag(clickedTag);
    86     }).click(function() {
   100     }).click(function() {
    87         clickedTag = lastTag;
   101         if (clickedTag == lastTag) {
       
   102             clickedTag = null
       
   103         } else {
       
   104             clickedTag = lastTag;
       
   105         }
    88         return false;
   106         return false;
    89     });
   107     });
    90     
   108     
    91     
   109     
    92     var chapters = myProject.getAnnotationsByTypeTitle("chapitrage"),
   110     var chapters = myProject.getAnnotationsByTypeTitle("chapitrage"),
   162         } else {
   180         } else {
   163             myMedia.pause();
   181             myMedia.pause();
   164         }
   182         }
   165         return false;
   183         return false;
   166     });
   184     });
   167     
   185         
   168     $(".progress-indicator").draggable({
       
   169         axis: "x",
       
   170         containment: "parent",
       
   171         drag: function(e, ui) {
       
   172             var t = myMedia.duration * parseInt(ui.helper.css("left")) / ( $(".chapters-bar").width() - 2 * ui.helper.width() );
       
   173             myMedia.setCurrentTime(t);
       
   174         }
       
   175     });
       
   176     
       
   177     var pictoTemplate = _.template(
   186     var pictoTemplate = _.template(
   178         '<li class="<%- type %>"><span class="picto"><a href="#"></a></span>'
   187         '<li class="<%- type %>"><span class="picto"><a href="#"></a></span>'
   179         + '<span class="picto-title"><%- annotation.title %></span></li>'
   188         + '<span class="picto-title"><%- annotation.title %></span></li>'
   180     );
   189     );
   181     
   190     
   261         
   270         
   262         currentAnnotation = annotationinfo;
   271         currentAnnotation = annotationinfo;
   263         
   272         
   264         annotationinfo.both.addClass("current");
   273         annotationinfo.both.addClass("current");
   265         
   274         
   266         $(".chapters-bar").addClass("annotation-onscreen");
   275         $(".timelines").addClass("annotation-onscreen");
   267         
   276         
   268         var annotationDiv = $(".annotation-templates ." + annotationinfo.type + "-annotation").clone();
   277         var annotationDiv = $(".annotation-templates ." + annotationinfo.type + "-annotation").clone();
   269         
   278         
   270         annotationDiv.appendTo($(".main-video"));
   279         annotationDiv.appendTo($(".main-video"));
   271         annotationDiv.find(".close-annotation").click(closeAnnotation);
   280         annotationDiv.find(".close-annotation").click(closeAnnotation);
   502                 var text = annotationinfo.annotation.content.text || annotationinfo.annotation.description;
   511                 var text = annotationinfo.annotation.content.text || annotationinfo.annotation.description;
   503                 
   512                 
   504                 switch (annotationinfo.annotation.content.markup) {
   513                 switch (annotationinfo.annotation.content.markup) {
   505                     case "html":
   514                     case "html":
   506                         annotationDiv.find(".text-contents").html(text);
   515                         annotationDiv.find(".text-contents").html(text);
   507 /*
   516 
   508                         var ps = annotationDiv.find(".text-contents>p"),
   517                         var ps = annotationDiv.find(".text-contents>p"),
   509                             groups = [],
   518                             groups = [],
   510                             last, group;
   519                             last, group;
   511                         ps.each(function(i, e) {
   520                         ps.each(function(i, e) {
   512                             if (last && group && last.nextElementSibling === e) {
   521                             if (last && group && last.nextElementSibling === e) {
   521                             last = e;
   530                             last = e;
   522                         });
   531                         });
   523                         groups.forEach(function(g) {
   532                         groups.forEach(function(g) {
   524                             $(g.master).replaceWith($('<div class="column-group">').append(g.contents));
   533                             $(g.master).replaceWith($('<div class="column-group">').append(g.contents));
   525                         });
   534                         });
   526 */
   535 
   527                     break;
   536                     break;
   528                     default:
   537                     default:
   529                         annotationDiv.find(".text-contents").html(
   538                         annotationDiv.find(".text-contents").html(
   530                             text.split(/\n/gm).map(function(l) {
   539                             text.split(/\n/gm).map(function(l) {
   531                                 return '<p>' + _.escape(l) + '</p>';
   540                                 return '<p>' + _.escape(l) + '</p>';
   556         if (currentAnnotation) {
   565         if (currentAnnotation) {
   557             closeAnnotation(true);
   566             closeAnnotation(true);
   558         }
   567         }
   559         return false;
   568         return false;
   560     });
   569     });
       
   570     
       
   571     function fullScreen() {
       
   572         var isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen,
       
   573             el = document.querySelector("body"),
       
   574             requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"],
       
   575             cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"];
       
   576         if (isFull) {
       
   577             for (var i = 0; i < cancelMethods.length; i++) {
       
   578                 if (typeof document[cancelMethods[i]] === "function") {
       
   579                     document[cancelMethods[i]]();
       
   580                     break;
       
   581                 }
       
   582             }
       
   583         } else {
       
   584             for (var i = 0; i < requestMethods.length; i++) {
       
   585                 if (typeof el[requestMethods[i]] === "function") {
       
   586                     el[requestMethods[i]]();
       
   587                     break;
       
   588                 }
       
   589             }
       
   590         }
       
   591         return false;
       
   592     }
       
   593     
       
   594     $(".full-screen").click(fullScreen);
       
   595     
       
   596     $(".about").click(function() {
       
   597         closeAnnotation();
       
   598         var aboutBox = $(".annotation-templates .about-box").clone().appendTo($(".main-video"));
       
   599         aboutBox.find(".close-annotation").click(closeAnnotation);
       
   600         aboutBox.css({ top: Math.floor(($(".main-video").height() - aboutBox.height())/2)+"px" });
       
   601     });
   561    
   602    
   562     function closeAnnotation(e) {
   603     function closeAnnotation(e) {
   563         currentAnnotation = null;
   604         currentAnnotation = null;
   564         $(".chip, .pictolist li").removeClass("current");
   605         $(".chip, .pictolist li").removeClass("current");
   565         $(".chapters-bar").removeClass("annotation-onscreen");
   606         $(".timelines").removeClass("annotation-onscreen");
   566         $(".annotation audio, .annotation video").each(function() {
   607         $(".annotation audio, .annotation video").each(function() {
   567             try {
   608             try {
   568                 this.pause();
   609                 this.pause();
   569             } catch(e) { }
   610             } catch(err) { }
   570         });
   611         });
   571         $(".main-video .annotation").hide().remove();
   612         $(".main-video .annotation").hide().remove();
   572         if (!!e) {
   613         if (!!e) {
   573             myMedia.play();
   614             myMedia.play();
   574         }
   615         }
   575         return false;
   616         return false;
   576     }   
   617     }
       
   618     
       
   619     var videoRatio = null;
       
   620     
       
   621     function repositionElements() {
       
   622         var videoel = $(".video-container video");
       
   623         if (!videoRatio) {
       
   624             videoRatio = videoel.width() / videoel.height();
       
   625         }
       
   626         if (!videoRatio) {
       
   627             return;
       
   628         }
       
   629         var container = $(".main-video"),
       
   630             ch = container.height(),
       
   631             cw = container.width(),
       
   632             vw = Math.min(cw, ch * videoRatio),
       
   633             vh = vw / videoRatio,
       
   634             dw = (cw - vw) / 2,
       
   635             dh = (ch - vh) / 2;
       
   636         videoel.css({
       
   637             width: vw,
       
   638             height: vh,
       
   639             "margin-top": dh
       
   640         });
       
   641         $(".pictolist").css({
       
   642             left: dw,
       
   643             bottom: dh
       
   644         });
       
   645     }
       
   646     
       
   647     $(".video-container video").on("loadedmetadata",repositionElements);
       
   648     
       
   649     $(window).resize(repositionElements);
       
   650     
       
   651     $(document).keydown(function(e) {
       
   652         if (e.keyCode === 122) {
       
   653             fullScreen();
       
   654             return false;
       
   655         }
       
   656     });
       
   657       
   577 });
   658 });
   578 
   659 
   579 };
   660 };