admin管理员组

文章数量:1305749

I am trying to implement a course portal where videos will be uploaded locally and will be available to students for studying. I am trying to create a interactive system: which will produce a question when the video reaches at a particular time.

For this I am using 'video-js' plugin for flash and HTML5 player. Now what I want to do is keeping track of time of video. Hence when the video reaches a particular time, I will be able to make a ajax call showing the question at particular time.

For this I am using 'durationchange' of video-js plugin. But it's only giving the 0th second as shown in following code

video1 = videojs('mplayer');
video1.on('durationchange', event);

var video1 = function(){

  currentTime = video1.currentTime; // nothing

}

How should I go about it. Please help me. Thanx.

I am trying to implement a course portal where videos will be uploaded locally and will be available to students for studying. I am trying to create a interactive system: which will produce a question when the video reaches at a particular time.

For this I am using 'video-js' plugin for flash and HTML5 player. Now what I want to do is keeping track of time of video. Hence when the video reaches a particular time, I will be able to make a ajax call showing the question at particular time.

For this I am using 'durationchange' of video-js plugin. But it's only giving the 0th second as shown in following code

video1 = videojs('mplayer');
video1.on('durationchange', event);

var video1 = function(){

  currentTime = video1.currentTime; // nothing

}

How should I go about it. Please help me. Thanx.

Share Improve this question asked Dec 30, 2013 at 14:13 phenom_aksphenom_aks 774 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

you actually need to be using the timeupdate event - durationchange is only fired if the duration of the video changes (usually when metadata finishes loading)

you can then track that currentTime property for the video:

using basic javascript

<video id="video" preload="auto" loop autoplay controls muted>     
    <source src="bigbuck.m4v" type='video/mp4' />
</video>

<div id="timer"> </div>

<script>
document.getElementById("video").addEventListener('timeupdate', function() {
    document.getElementById("timer").innerHTML = this.currentTime;
    currentTime = this.currentTime;
});
</script>

本文标签: javascriptVideojsGetting timestamp of video dynamicallyStack Overflow