app.controller('cutCtrl', function ($scope, $http,video,notify) { $scope.inicio=0; $scope.fin=0; $scope.curso=""; $scope.desc=""; $scope.video = video; $scope.censuras = []; $scope.timings = video["timings"] ? video["timings"] : []; document.getElementById("video").setAttribute("src", $scope.video.file); $scope.post = function() { var data = { curso: $scope.curso, desc: $scope.desc, inicio: $scope.inicio, fin: $scope.fin, id: $scope.video._id, censuras: $scope.censuras }; $http.post('/back/crop/', data) .success(function(data,state) { notify({message:data.status,classes:"alert"}); }) .error(function(data) { notify({message:data.status,classes:"alert alert-danger"}); }); }; $scope.obtenerTiempos = function() { $http.get('/back/timings/' + $scope.video._id) .success(function(data, state) { $scope.timings = data["timings"]; }); }; $scope.formatearTiempo = function(t) { var h = parseInt(t/3600); var m = parseInt((t % 3600) / 60); var s = parseInt(t % 60); if (m < 10) m = "0" + m; if (s < 10) s = "0" + s; return `${h}:${m}:${s}`; } $scope.borrarCensura = function(c) { var i = 0; for ( i = 0; i < $scope.censuras.length; i++) { if ( $scope.censuras[i] == c ) { $scope.censuras.splice(i,1); return; } } }; $scope.agregarCensura = function(){ for ( var i = 0; i < $scope.censuras.length; i++) if ($scope.censuras[i].inicio == 0) return; $scope.censuras.push({inicio:0,fin:0}); } function getVideoTime(){ var video = document.getElementById("video"); return video.currentTime; } $scope.changeTimeAbs = function(t) { if (t === undefined) return; var video = document.getElementById("video"); video.currentTime=t; } $scope.changeTime = function(t) { if (t === undefined) return; var video = document.getElementById("video"); video.currentTime=video.currentTime+t; } $scope.setEnd = function() { $scope.fin=getVideoTime(); }; $scope.setStart = function() { $scope.inicio=getVideoTime(); }; });