var tettool_videoController={init:function init(Label,$tetitem){console.log("tet.tool",$tetitem.attr("id"),$tetitem.attr("itemtitle"));var player=$tetitem;var video=get_tettool_param($tetitem,"video").trim();var slow=get_tettool_param($tetitem,"slow","1/10").trim();var reverse=0;var seconds=get_tettool_param($tetitem,"seconds");var step=get_tettool_param($tetitem,"step");if(video){video=$tet(video).find("video")}else{var tpCh=player.attr("tpCh");video=$('.tetitem[itemtype=mov][tpCh="'+tpCh+'"]').find("video")}if(!video.length){video=$("video")}var ppb=player.find(".ppBtn");var pp2b=player.find(".pp2Btn");var pprb=player.find(".pprBtn");var ppr2b=player.find(".ppr2Btn");var sf=player.find(".stFwBtn");var sb=player.find(".stBwBtn");var pb=player.find(".progressBar");var tc=player.find(".timeCode");if(!reverse){pprb.hide();ppr2b.hide()}if(!step){sf.hide();sb.hide()}if(slow){pp2b.attr("slowspeed",slow);ppr2b.attr("slowspeed",slow)}else{pp2b.hide();ppr2b.hide()}if(seconds){tc.addClass("secs")}player.attr("ignoreDblClick","ignoreDblClick");function PP(speed){var ppNow=function(e){if(video===undefined){return}var isPaused=video[0].paused;video.each(function(){if(isPaused){if(speed<0){if(this.currentTime===0){this.currentTime=this.duration}}this.playbackRate=speed;this.play()}else{this.pause()}})};return ppNow}function SFB(dir){var makeOneStep=function(e){if(video===undefined){return}var isPaused=video[0].paused;video.each(function(){var fps=video_ana_getFPS(this);if(!isPaused){this.pause()}this.currentTime+=(dir/fps)})};return makeOneStep}ppb.on("click",PP(1));pp2b.on("click",PP(eval(slow)));pprb.on("click",PP(-1));ppr2b.on("click",PP(-eval(slow)));sf.on("click",SFB(1));sb.on("click",SFB(-1));pb.on("mousedown.va touchstart.va",function(e){e.preventDefault();var cssScale=$(this).parents(".tetitem_inner").get().reduce(function(totalScale,el){return totalScale*(get_css_transform(el).scale||1)},1);e=(e.originalEvent.touches)?e.originalEvent.touches[0]:e;var xAbs=e.clientX-$(this).offset().left;var xRel=xAbs/$(this).width()/cssScale;function videoTimeChangeRel(xRel){function limit(d){return d<0?0:d>1?1:d}if(video===undefined){return}var trel=limit(xRel);pb.children("div").css("width",100*trel+"%");var ct=video[0].duration*trel;tc.html(!seconds?hms(ct):Math.round(ct*100)/100);video.each(function(){this.currentTime=ct})}videoTimeChangeRel(xRel);$(document).on("mousemove.va touchmove.va",function(e){var _this=pb;e.preventDefault();e=(e.originalEvent.touches)?e.originalEvent.touches[0]:e;var xAbs=e.clientX-$(_this).offset().left;var xRel=xAbs/$(_this).width()/cssScale;videoTimeChangeRel(xRel)});$(document).one("mouseup.va touchend.va",function(){pb.off("mousemove.va touchmove.va");$(document).off("mousemove.va touchmove.va")})});if(video.length){video_ana_initVid(player,video)}else{alert("Video Player ohne Video")}function video_ana_initVid(player,video){var player_id=player.attr("id");video.removeAttr("controls");video.each(function(){this.load();this.pause()});var ppb=player.find(".ppBtn,.pp2Btn,.pprBtn,.ppr2Btn");var pb=player.find(".progressBar");var tc=player.find(".timeCode");var updatePlayButtons=function updatePlayButtons(isPaused){if(isPaused){ppb.removeClass("tetvideoplayer_pause").addClass("tetvideoplayer_play")}else{ppb.removeClass("tetvideoplayer_play").addClass("tetvideoplayer_pause")}};updatePlayButtons(true);video.eq(0).on("play."+player_id+" pause."+player_id,function(e){updatePlayButtons(e.type=="pause")}).on("timeupdate."+player_id,function(){var ct=this.currentTime;var d=this.duration;pb.children("div").css("width",100*ct/d+"%");tc.html(!seconds?hms(this.currentTime):Math.round(this.currentTime*100)/100)})}},};function hms(g){if(isNaN(g)||!isFinite(g)){console.log("hms() audio error: invalid time");return"0:00"}var d=Math.floor(g/3600);g-=3600*d;var a=Math.floor(g/60);g-=60*a;var c=Math.floor(g);var f=String(d);var b=String(a);var e=String(c);var i="";if(d>0){i=f+":"}if(a>=10||d==0){i=i+b+":"}else{i=i+"0"+b+":"}if(c>=10){i=i+e}else{i=i+"0"+e}return i}function video_ana_getFPS(a){return 25};