javascript - 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
解决方案
player.currentTime(localStorage.currentTime);
无法工作,因为 localStorage 中的值存储为字符串。改为使用player.currentTime(parseFloat(localStorage.currentTime));
。
推荐阅读
- imagemagick - Imagemagick 动画师在制作 gif 时不断调整我的图像大小
- powerbi - Power Apps 上的预测预算工具
- qt - How to add text onto QToolbar with Qt Designer?
- flutter - 访问firestore中的数组并找到打印(如果存在)
- swiftui - onChange not firing when attached to a Picker
- regex - 正则表达式模式替换
- c++ - How to initialize std::map by an array?
- boost - install boost armhf from apt
- html - Html and CSS: Unable to Change Background Color of Container
- javascript - Use Right to Left Text in an SVG Text Element Using JavaScript