【发布时间】:2017-04-29 15:32:47
【问题描述】:
我有两个必须相互通信的控制器。 第一个引用视频播放器,第二个引用时间轴。
从第一个,我得到了视频播放的currentTime,我想将它传递给第二个,它应该在视频播放时移动时间栏。
我尝试使用工厂在控制器之间共享一个名为 time 的变量,但这在此期间不会改变。
第一控制器:
angular.module('videoCtrl', ['vjs.video'])
.controller('videoController', ['$scope', 'Timeline', function (scope, Timeline) {
scope.mediaToggle = {
sources: [
{
src: 'http://static.videogular.com/assets/videos/videogular.mp4',
type: 'video/mp4'
}
],
};
//listen for when the vjs-media object changes
scope.$on('vjsVideoReady', function (e, videoData) {
videoData.player.on('timeupdate', function () {
var time = this.currentTime();
Timeline.setTime(time); // setting the time on factory
})
});
}]);
第二控制器:
angular.module('timelineCtrl', ['mt.media-timeline'])
.controller('timelineController', function ($scope, Timeline) {
$scope.time = Timeline.getTime(); // here I'm trying to get the time
});
工厂:
.factory('Timeline', function(){
var timelines = [];
var time = null;
return {
getTime: function() {
return time;
},
setTime: function(_time) {
time = _time;
}
}
});
【问题讨论】:
标签: angularjs