【问题标题】:How to restore the pause time of vimeo on page reload using localStorage?如何使用localStorage恢复页面重新加载时vimeo的暂停时间?
【发布时间】:2020-04-19 04:29:30
【问题描述】:

我正在尝试创建一个 jquery 脚本来存储 vimeo 视频的暂停时间,这样当他回来时,他可以从他离开的地方观看它

jQuery(document).ready(function() {
    player.on('pause', function() {
        console.log("pause");   
    });
});

我想使用本地存储来实现这一点

【问题讨论】:

    标签: javascript jquery vimeo


    【解决方案1】:

    你已经知道你需要什么积木了,现在你只需要把它们放在一起。

    使用Vimeo Player API,您可以获取vimeo 实例和get the player time when the video pauses

    然后使用localStorage APIstore the data

    加载页面时,只需 check localStorage if data is present 并再次使用 Vimeo Player API 到 set the current time 如果是这样。

    let time = localStorage.getItem('videoProgress');
    if(time != null) {
        player.setCurrentTime(time);
    }
    
    player.on('pause', function() {
        player.getCurrentTime().then(function(seconds) {
            localStorage.setItem('videoProgress', seconds);
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      相关资源
      最近更新 更多