Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

javascript - HTML5 Video API: Cannot Pause On Last Frame If Looping Enabled

Trying to pause a video on the very last frame appears to not work if the video is on the very last frame.

var app = angular.module('myApp', []);

app.controller('MainCtrl', function ($scope) {

})

app.directive('someVideo', function ($window, $timeout) {
    return {
    	  controller: function($scope) {
        
        },
        link: function (scope, elm) {
            scope.videoPlayer = elm[0];
            scope.keyDownEvent = keyDownEvent;
            scope.currentTime = 0;
            scope.videoPlayer.loop = true;
            
            angular.element($window).bind('keydown',scope.keyDownEvent);
            
            function keyDownEvent(e){
            console.log(e.keyCode);
              	switch(e.keyCode) {
                    case 32: //space
                    	scope.videoPlayer.loop = !scope.videoPlayer.loop;
                    	console.log('spcae: ',scope.videoPlayer.loop);
                      break;
	              	  case 38: //up
	  			            scope.videoPlayer.currentTime = 0;
                      console.log('up: ', scope.videoPlayer.currentTime);
											break;
                		case 40: //down
                      scope.videoPlayer.pause();
											scope.videoPlayer.currentTime = scope.videoPlayer.duration;
                      console.log('down: ', scope.videoPlayer.currentTime);
											break;
              	}
            }
        }
    }
})
body {
  overflow: hidden;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<div ng-app="myApp">
    <div ng-controller="MainCtrl">
        <video some-video src="http://nagi.ca/u/google.mp4" autoplay></video>
    </div>
</div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change this

scope.videoPlayer.currentTime = scope.videoPlayer.duration;

to this

scope.videoPlayer.currentTime = scope.videoPlayer.duration - 1;

JSFiddle: http://jsfiddle.net/hopkins_matt/4bygou77/5/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...