UNPKG

unserver-unify

Version:

193 lines (177 loc) 6.99 kB
angular.module('bamboo.course').controller('MP3PPTCtrl', function($scope, $timeout, $sce, CommonService, $stateParams, ApiService, CourseApi, $state, AppConfig) { var self = this; this.cid = $stateParams.cid; this.id = $stateParams.rid; console.log($stateParams); // this.chapter = {}; console.log("---- chapter Item -----"); this.mediapath = ApiService.SHOST + '/lcourse/' + self.cid + '/resources/'; this.pptpicurl = this.pptaudiourl = this.ResUrl = ApiService.SHOST + '/lcourse/'; var _lasttime = new Date(); var videoComplete = false; $scope.$on("$destroy", function() { var mp4time = (self.API.totalTime!=self.API.currentTime)?parseInt(self.API.currentTime / 1000):0; CourseApi.recordUsage(self.cid,self.id,$stateParams.mvid,_lasttime,mp4time,videoComplete); }); this.getMediaUrl = function() { var fullurl = self.ResUrl + (self.chapter.rid || self.chapter.cid) + "/resources/" + encodeURI(self.chapter.content); console.log(fullurl); return $sce.trustAsResourceUrl(fullurl); }; this.getSubUrl = function() { // var suburl=ApiService.MEDIAPATH+ '/lcourse/'+ ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.chapter.subtitle; var suburl = ApiService.MEDIAPATH + '/lcourse/' + (self.chapter.rid || self.chapter.cid) + "/resources/" + self.chapter.subtitle; console.log(suburl); if (ApiService.MEDIAPATH && self.chapter.subtitle) { return $sce.trustAsResourceUrl(encodeURI(suburl)); } else { return null; } } this.getPPtPicUrl = function(url) { console.log(url); return $sce.trustAsResourceUrl(self.ResUrl + (self.chapter.rid || self.chapter.cid) + "/resources/" + encodeURI(url)); }; function getAudioUrl(url) { console.log(self.mediapath + url); return $sce.trustAsResourceUrl(self.mediapath + encodeURI(url)); }; this.getOnlineVideoUrl = function() { return $sce.trustAsResourceUrl(self.chapter.content); }; self.API = null; this.onPlayerReady = function(API) { self.API = API; }; this.videoCanPlay = function() { $timeout(function() { self.API.play();  }, 500); }; this.audioPause = true; this.onUpdateState = function($state) { console.log($state); self.audioPause = ($state == 'pause') ? true : false; } this.audioPptFinish = function() { self.displayImg = undefined; } this.onVideoFinished = function() { console.log("------------------- video play finished : "); videoComplete = true; }; function getInfo() { self.displayImg = null; var info = { action: 'getresource', id: self.id, }; CourseApi.mvApi(info, function(result) { // CommonService.stopLoading(); console.log(result); if(result.success){ self.chapter = result.data; if (self.chapter.cid != self.cid) { self.mediapath = ApiService.SHOST + '/lcourse/' + self.chapter.cid + '/resources/'; } self.mp4config = { sources: [{}], // theme: 'css/videogular-themes-default/videogular.min.css', tracks: [{ src: "", kind: "subtitles", srclang: "en", label: "English", default: "true" }] }; if(self.chapter.type == 'youtube' || self.chapter.type == 'vimeo') { self.mp4config.sources[0].src = self.getOnlineVideoUrl(); } else { getRecordUsage(); self.mp4config.sources[0].src = self.getMediaUrl(); self.mp4config.sources[0].type = 'video/mp4'; if (self.chapter.type == 'mp3ppt') { self.mp4config.sources[0].type = 'audio/mp3'; } self.mp4config.tracks[0].src = self.getSubUrl(); $scope.topLevelAudio = $scope.audio = null; if (self.chapter.type == 'mp4ppt' || self.chapter.type == 'mp3ppt') { self.uploadedImgs = self.chapter.ppts; var cues = [] console.info(self.uploadedImgs); for (var i = 0; i < self.uploadedImgs.length; i += 1) { // only care about linked imgs //var endTime = getNextLinkCuePoint(i,_self.uploadedImgs); //var endTime = null; //console.log(endTime); if (self.uploadedImgs[i].linked) { var endTime = self.uploadedImgs[i].cueDuration && (self.uploadedImgs[i].cueTime + (parseInt(self.uploadedImgs[i].cueDuration) || 0)); if (self.uploadedImgs[i].forever) { endTime = self.uploadedImgs[i].cueDuration; } var cue = { timeLapse: { start: self.uploadedImgs[i].cueTime, end: endTime }, onEnter: self.onEnterCuePoint2.bind(self), onLeave: self.onLeaveCuePoint.bind(self), onUpdate: self.onLeaveCuePoint.bind(self), onComplete: self.onCompleteCuePoint.bind(self), params: { displayImg: self.uploadedImgs[i], index: i, } } if (!self.uploadedImgs[i].cueDuration && self.uploadedImgs[i].cueDuration != 0) { delete cue.timeLapse.end; } cues.push(cue); } } self.mp4config.cuePoints = {}; self.mp4config.cuePoints.imgswitch = cues; } if (self.chapter.audio) { self.audiourl = getAudioUrl(self.chapter.audio); console.log(self.audiourl); } } } console.log(self.mp4config); }); } getInfo(); this.onLeaveCuePoint = function(currentTime, timeLapse, params) {} this.onCompleteCuePoint = function(currentTime, timeLapse, params) { console.info("onCompleteCuePoint", currentTime, timeLapse, params); if (params.index == self.currIndex) { $timeout(function() { self.displayImg = null; }, 500); } } this.onEnterCuePoint2 = function(currentTime, timeLapse, params) { console.log("onEnterCuePoint", currentTime, timeLapse, params); self.currIndex = params.index; $timeout(function() { self.displayImg = params.displayImg; }, 500); } function getRecordUsage() { var info = { action: "getResourceUsage", rid: self.id }; console.log(info); CourseApi.mvApi(info, function(data) { console.log(data); if(data.success&&data.data&&data.data.mp4time) { self.API.seekTime(data.data.mp4time, false);  } }); } });