首页 > 解决方案 > videojs 插件的 currentTime() 方法不起作用

问题描述

我正在使用 Videojs 插件作为视频播放器;我想要第二次重新启动播放器时;从我离开播放器之前的位置开始播放视频。

<div id="playerDiv">
      <video id="my_video_1" class="video-js vjs-default-skin"  controls preload="none">
            <source src="http://xxxxxx/stepupallin_en_fr_ts.mpg"  type='video/mpg' id="videosrc" />
      </video>
 </div>

播放我使用的视频:

$('#playerDiv').append('<video id="my_video_1" class="video-js vjs-default-skin"  controls preload="none" ><source src="http://xxxx/stepupallin_en_fr_ts.mpg" type="video/mpg"></video>');
    player = videojs("my_video_1"); 
    player.play();

离开我使用的播放器: whereYouAt = player.currentTime();//获取视频之前的位置 //离开它 var currentTime = localStorage.currentTime; localStorage.currentTime = whereYouAt; player.dispose();

当我第二次播放视频时:

player.currentTime(localStorage.currentTime); 

但我不知道为什么它不起作用

我也尝试使用偏移量,但它不起作用:

player.offset({
    start: localStorage.currentTime,
    end: localStorage.duration,
    restart_beginning: false 
});

我想要的只是从给定时间播放videojs

标签: javascriptjqueryvideo.js

解决方案


player.currentTime(localStorage.currentTime); 无法工作,因为 localStorage 中的值存储为字符串。改为使用player.currentTime(parseFloat(localStorage.currentTime));


推荐阅读