我有一个视频要在达到 X 秒后暂停。
- 我可以播放视频
我可以通过以下方式收听 currentTime:
<videogular data-vg-update-time="someFunction($currentTime,$duration)" ...> </videogular>
我可以在控制器中捕捉到我正在寻找的时间:
var controllers = {}; controllers.SomeController = function($scope){ $scope.someFunction($currentTime, $duration){ // this is a total hack method to catch current time // stay in school or you'll write code like this if(Math.round($currentTime) === 6){ // RIGHT HERE. I know the API must be exposing the video obj // but I haven't been able to figure out how to catch it. // // var foo = document.getElementsByTagName('video'); // foo.pause(); } } } myApp.controller(controllers);
现在,显然有更好的方法来解决这个问题。闻起来很糟糕,我放弃了角度来评估 currentTime,并尝试识别视频对象。在某种程度上,我正在挣扎,因为该对象是通过嵌入 Videogular 的指令创建的。我的控制器+部分看起来像:
[continued from above...]
[i.e controllers.SomeController = function($sce, $scope){
// this is the angular controller
$scope.attractConfig = {
sources: [
{src: $sce.trustAsResourceUrl("/video/myVideo.mp4"), type: "video/mp4"}
],
theme: "/bower_components/videogular-themes-default/videogular.css",
plugins: {
poster: "http://www.videogular.com/assets/images/videogular.png"
},
autoPlay: true
};
// and this is the HTML partial
<div data-ng-controller="SomeController as controller">
<videogular data-vg-theme="attractConfig.theme"
data-vg-auto-play="attractConfig.autoPlay"
data-vg-update-time="checkAttractTime($currentTime,$duration)"
data-vg-complete="restartAttract()">
<vg-media data-vg-src="attractConfig.sources"></vg-media>
</videogular>
</div>
我觉得我已经走了 90% 的路,但我不知道如何在 currentTime 达到 X 秒时直接调用 pause() 或 play() 。我不知道如何定位通过指令出现的视频对象。