如何使用localStorage恢复页面重新加载时vimeo的暂停时间?

问题描述 投票:1回答:1

我正在尝试创建一个jquery脚本来存储vimeo视频的暂停时间,以便他回来时可以从上次中断的地方观看它

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

我想使用本地存储实现此目的

javascript jquery vimeo
1个回答
0
投票

您已经确定了所需的砖块,现在只需要将它们放在一起。

使用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);
    });
});
© www.soinside.com 2019 - 2024. All rights reserved.