2016-10-18 196 views
0

我在一個項目中使用ngVideo,我不知道如何從控制器獲取/設置當前時間。從控制器控制ngVideo對象

我的控制器:

'use strict'; 

angular.module('clientApp') 
.config(function($stateProvider){ 
    $stateProvider 
    .state('video', { 
    url:'/video', 
    templateUrl:'views/video.html', 
    controller:'VideoController as video' 
    }); 
}) 
.controller('VideoController', function($scope, video){ 
    video.addSource('mp4', 'views/unit_1.mp4'); 
    video.currentTime = 10; 
    console.log('Current Time: ' video.currentTime); 

}); 

我的HTML:

<section class="video" ng-video> 
    <video vi-screen></video> 
<section vi-feedback> 

    <ul> 
     <li>Time: {{currentTime}}s/{{duration}}s</li> 
     <li>Volume: {{volume}}</li> 
     <li>Buffered: {{buffered}}%</li> 
     <li>Loading: {{loading}}</li> 
     <li>Playing: {{playing}}</li> 
    </ul> 

</section> 
</section> 

回答

1
video.currentTime = 10; 

應該設置時間。我想創建一個函數來設置時間,如果你需要在類似代碼的其他地方重置:

$scope.setCurrentTime = function(newTime) { 
    video.currentTime = newTime; 
}; 

然後,您可以從表格或其他代碼調用它:

<button ng-click="setCurrentTime(30)">Set to 30</button> 

if (some condition) { 
    $scope.setCurrentTime(30); 
} 

,或者可以將視頻體積到輸入字段(沒有功能)結合:

<input id="videoTime" ng-model="video.currentTime" /> 

希望有幫助!