<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<video src=""></video>
<video id="video1" width="420" style="margin-top:15px;" controls="" autoplay="" name="media">
<source src="http://www.w3school.com.cn/example/html5/mov_bbb.mp4?t=7" type="video/mp4" /> Your browser does not support HTML5 video.
</video>
</body>
<script>
var a = document.getElementById("video1");
var timespan = 0;
var isCountTime = false;
a.onplaying = function () {
isCountTime = true;
console.log("playing");
}
a.onwaiting = function () {
isCountTime = false;
console.log("waiting");
}
a.onpause = function () {
isCountTime = false;
console.log("pasused");
}
setInterval(function () {
if (isCountTime) {
timespan += 0.1;
console.log(timespan);
}
}, 100);
</script>
</html>