如何将每个视频持续时间和 url 存储在单独的本地存储变量中? (Vimeo,Jquery)
How to store every video duration and url in separate local storage variable? (Vimeo,Jquery)
基本上我正在尝试将视频 url 和持续时间存储在本地存储中,但我想对任何视频都这样做
它只适用于一个我不在乎本地存储有多少保存每个视频 url 和持续时间分开?
jQuery(document).ready(function() {
let prev_url= localStorage.getItem('videourl');
player.getDuration().then(function(duration) {
var minutes = Math.floor(duration / 60);
jQuery('#total_minutes').html('<i class="fal fa-clock"></i>'+minutes+' minutes');
});
jQuery('.video_trailer_embed').each(function(){
var href = jQuery(this).attr('src');
if(href==prev_url || prev_url==null) {
localStorage.setItem('videourl', href);
let time = localStorage.getItem('videoProgress');
player.setCurrentTime(time);
}
function run_url_every_2seconds(){
localStorage.setItem('videourl', href);
console.log(href);
}
player.on('play', function() {
setInterval(run_url_every_2seconds,2000);
});
});
/*player.on('pause', function() {
player.getCurrentTime().then(function(seconds) {
localStorage.setItem('videoProgress', seconds);
});
}); */
function run_every_2seconds(){
player.getCurrentTime().then(function(seconds) {
localStorage.setItem('videoProgress', seconds);
});
}
player.on('play', function() {
setInterval(run_every_2seconds,2000);
});
为每个 localStorage 键添加一个索引 i
以使每个页面上的名称不同。并添加 window.location.pathname
以区分页面。否则,您每次都会覆盖存储中的相同值。
jQuery('.video_trailer_embed').each(function(i){
var href = jQuery(this).attr('src');
if(href==prev_url || prev_url==null) {
localStorage.setItem('videourl' + window.location.pathname + i, href);
let time = localStorage.getItem('videoProgress' + window.location.pathname + i);
player.setCurrentTime(time);
}
function run_url_every_2seconds(){
localStorage.setItem('videourl' + window.location.pathname + i, href);
console.log(href);
}
player.on('play', function() {
setInterval(run_url_every_2seconds,2000);
});
});
基本上我正在尝试将视频 url 和持续时间存储在本地存储中,但我想对任何视频都这样做 它只适用于一个我不在乎本地存储有多少保存每个视频 url 和持续时间分开?
jQuery(document).ready(function() {
let prev_url= localStorage.getItem('videourl');
player.getDuration().then(function(duration) {
var minutes = Math.floor(duration / 60);
jQuery('#total_minutes').html('<i class="fal fa-clock"></i>'+minutes+' minutes');
});
jQuery('.video_trailer_embed').each(function(){
var href = jQuery(this).attr('src');
if(href==prev_url || prev_url==null) {
localStorage.setItem('videourl', href);
let time = localStorage.getItem('videoProgress');
player.setCurrentTime(time);
}
function run_url_every_2seconds(){
localStorage.setItem('videourl', href);
console.log(href);
}
player.on('play', function() {
setInterval(run_url_every_2seconds,2000);
});
});
/*player.on('pause', function() {
player.getCurrentTime().then(function(seconds) {
localStorage.setItem('videoProgress', seconds);
});
}); */
function run_every_2seconds(){
player.getCurrentTime().then(function(seconds) {
localStorage.setItem('videoProgress', seconds);
});
}
player.on('play', function() {
setInterval(run_every_2seconds,2000);
});
为每个 localStorage 键添加一个索引 i
以使每个页面上的名称不同。并添加 window.location.pathname
以区分页面。否则,您每次都会覆盖存储中的相同值。
jQuery('.video_trailer_embed').each(function(i){
var href = jQuery(this).attr('src');
if(href==prev_url || prev_url==null) {
localStorage.setItem('videourl' + window.location.pathname + i, href);
let time = localStorage.getItem('videoProgress' + window.location.pathname + i);
player.setCurrentTime(time);
}
function run_url_every_2seconds(){
localStorage.setItem('videourl' + window.location.pathname + i, href);
console.log(href);
}
player.on('play', function() {
setInterval(run_url_every_2seconds,2000);
});
});