简体   繁体   中英

Videojs Display current time through out video

I'm struggling to see how to display the current video position of video and update the timer.

I want the current video time to continuously display in the div #time_count The code I have is

            <link href="//vjs.zencdn.net/4.11/video-js.css" rel="stylesheet">
            <script src="//vjs.zencdn.net/4.11/video.js"></script>

            <video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"
              poster="http://video-js.zencoder.com/oceans-clip.png"
              data-setup='{"example_option":true}'>
             <source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
            </video>
            <div id="time_count"></div>
            <script>

            (function() {
                var myPlayer;
                var myTextArea = document.getElementById('time_count');

                videojs("example_video_1").ready(function(){

                    myPlayer = this;
                    myPlayer.play();
                    myPlayer.on("progress", onProgress);
                });


                function onProgress() {
                console.log(myPlayer.duration());
                  myTextArea.innerHTML = myPlayer.currentTime();
                  return false;
                }

            })();
            </script>

Any ideas?

在添加评论之后,我发现解决方案应该使用timeupdate,因此它将是myPlayer.on(“ timeupdate”,onProgress)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM