gpt4 book ai didi

javascript - 检测到视频正在 javascript 插件 plyr 中播放

转载 作者:行者123 更新时间:2023-12-05 06:34:25 26 4
gpt4 key购买 nike

我正在使用此处的 plyr javascript 插件 - https://github.com/sampotts/plyr我需要检测用户正在观看视频。最后,我将添加使用 AJAX 收集统计信息的代码。但是下面的代码不起作用。

const player = new Plyr('#video1', {
controls: ['play-large', 'play', 'progress', 'current-time', 'captions', 'fullscreen', 'settings']
});

jQuery(function ($) {
if (player.playing) {
alert ("playing!!");
}
});

最佳答案

    var plyrView = false; // Has he watched it before?
var videoId = 123456;
var counter = 0;
document.addEventListener('DOMContentLoaded', () => {
const player = new Plyr('#player');
window.player = player;
$('.plyr').click(function() {
if (plyrView == false) {
setTimeout(function() {
var divPlaying = $('div').hasClass('plyr--playing');
if (player.playing == true && divPlaying == true && plyrView == false) {
$.ajax({
type: 'post',
url: 'ajax.php',
data: { 'videoId': videoId },
success: function(viewVideo) {
if (viewVideo == 'success') {
plyrView = true;
counter++;
} else {
// Error Code
}
}
});
}
}, 3000);
}
});
});

关于javascript - 检测到视频正在 javascript 插件 plyr 中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50281525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com