【问题标题】:Detect that the video is playing in javascript plugin plyr检测视频是否在 javascript 插件 plyr 中播放
【发布时间】:2018-05-10 21:08:00
【问题描述】:

我在这里使用 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!!");
    }
});

【问题讨论】:

  • 你有什么解决办法请发帖

标签: javascript plyr.js


【解决方案1】:
    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);
            }
        });
    }); 
 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 2021-12-24
    • 2014-10-11
    • 2012-01-25
    相关资源
    最近更新 更多