$(function(){; var globalModule = window; var player = function(args){ this.init(args); } player.prototype = { init : function(args){ this.el = args.el; this.domain = args.domain; this.playVideoUri = args.playVideoUri; this.video_js = args.video_js; this.videoList = args.videoList; this.videoListItemSelector = args.videoListItemSelector; this.playFromList = false; this.setHandlers(); }, setHandlers : function(){ $(this.el).find(".playToggle").on("click" , $.proxy(this.handlers.play,this) ); $(this.el).find(".prevTrack").on("click" , $.proxy(this.handlers.prevTrack,this) ); $(this.el).find(".nextTrack").on("click" , $.proxy(this.handlers.nextTrack,this) ); $(this.el).find(".forwardTime").on("click" , $.proxy(this.handlers.forwardTime,this) ); $(this.el).find(".scan").on("click" , $.proxy(this.handlers.scan,this) ); $(this.el).find(".like").on("click" , $.proxy(this.handlers.like,this) ); $(this.el).find(".reverseTime").on("click" , $.proxy(this.handlers.reverseTime,this) ); $(this.el).find(".fullScreen").on("click" , $.proxy(this.handlers.fullScreen,this) ); $(this.el).find(".link").on("click" , $.proxy(this.handlers.link,this) ); if( this.videoList ){ this.playFromList = true; this.playList(); } } , playList: function(){ var items = $( this.videoList).find(this.videoListItemSelector); var active = items.first(); if(items.find(".active").length > 0){ active = items.find(".active").first(); } active.addClass("active"); // need more 'actives' var url = $(active).attr("attr-link"); this.setSource(url); }, handlers : { play : function(){ var $vid_obj = this.video_js ; var playEl = $(this.el).find(".playToggle"); if ( $vid_obj.techGet('paused') === false ) { var play = '
'; $(playEl).empty(); $(playEl).html(play); $vid_obj.pause(); } else { var pause = '
'; $(playEl).empty(); $(playEl).html(pause); $vid_obj.play(); } }, prevTrack: function () { if(this.playFromList){ var items = $( this.videoList).find(this.videoListItemSelector); var active = $( this.videoList).find(this.videoListItemSelector + ".active").first(); var prev = $(active.prev()); if(prev.length == 0){ prev = items.last(); } active.removeClass("active"); prev.addClass("active"); var url = prev.attr("attr-link"); this.setSource(url); }else{ } }, forwardTime: function() { var $vid_obj = this.video_js; $vid_obj.currentTime( $vid_obj.cache_.currentTime + 3 ); }, nextTrack: function () { if(this.playFromList){ var items = $( this.videoList).find(this.videoListItemSelector); var active = $( this.videoList).find(this.videoListItemSelector + ".active").first(); var next = $(active.next()); if(next.length == 0){ next = items.first(); } active.removeClass("active"); next.addClass("active"); var url = next.attr("attr-link"); this.setSource(url); }else{ } }, scan: function() { console.log('scan'); }, like: function () { console.log('like'); }, reverseTime: function (){ var $vid_obj = this.video_js; if ( $vid_obj.cache_.currentTime > 4 ) { $vid_obj.currentTime( $vid_obj.cache_.currentTime - 3 ); } }, fullScreen: function () { var $vid_obj = this.video_js; if ( !$vid_obj.isFullScreen ) { $vid_obj.requestFullScreen(); } else { $vid_obj.cancelFullScreen(); } }, link: function(){ var $vid_obj = this.video_js; var url = $vid_obj.cache_.src.replace(base,''); window.open(url); } }, setSource : function(src) { var $vid_obj = this.video_js; var base = this.domain + this.playVideoUri; var options = $vid_obj.options(); var $target = base+src; var filename = src.replace(/([\.\=\?\/\:])/g, "_"); console.log("filename is: "+filename); var controlBar = $("#" + options.id + " .vjs-control-bar"); var bigPlayButton = $("#" + options.id + " .vjs-big-play-button"); bigPlayButton.hide(); $vid_obj.pause(); // assign the target video to the source node $vid_obj.src({src: $target, type: 'video/flv'}); // load the new source $vid_obj.load(); controlBar.addClass('vjs-control-hide'); $vid_obj.posterImage.show(); $vid_obj.on("loadedmetadata", function () { bigPlayButton.show(); //controlBar.removeClass('vjs-control-hide'); }); } } globalModule.playerCreate = player; });