在角度控制器中捕获html5视频事件

时间:2015-12-21 19:12:40

标签: javascript html angularjs html5 angularjs-directive

<video id="video-player" ng-click="togglePlayer($event)" 
       oncontextmenu="return false" autoplay="true" loop 
       class="composition-video" ng-src="{{url}}" type="video/mp4"></video>

如何在angularjs中控制器中视频播放器状态发生变化时捕获事件?

1 个答案:

答案 0 :(得分:0)

这是一种使用指令添加侦听器到视频元素的可能方法:

http://plnkr.co/edit/dOm5TnGiSkJAUAtXSFa1?p=preview

.directive('videoEvents', function () {
    return function ($scope, $element) {
      $element[0].addEventListener("loadeddata", function () {
        console.log('loadeddata');
        // you can $rootScope.$broadcast...
      });
      $element[0].addEventListener("playing", function () {
        console.log('playing');
        // you can $rootScope.$broadcast...
      });
      // and so on...
    }
});