Video.js+移动设备上的谷歌IMA:'点击'导致错误的事件

Video.js + google IMA on mobile devices: 'tap' event causing errors

本文关键字:点击 事件 错误 IMA 移动 js+ Video 谷歌      更新时间:2023-09-26

我正在尝试使用video.js和谷歌的IMA插件[videojs-ima][1] 实现显示视频广告

在示例代码中有以下部分:

// Initialize the ad container when the video player is clicked, but only the
// first time it's clicked.
var startEvent = 'click';
if (navigator.userAgent.match(/iPhone/i) ||
    navigator.userAgent.match(/iPad/i) ||
    navigator.userAgent.match(/Android/i)) {
  startEvent = 'tap';
}

但当移动设备上的startEvent设置为tap时,我会出现以下错误:

Uncaught TypeError: document.createTouch is not a function(anonymous function) @ ima3.js:252Ha @ ima3.js:9zm @ ima3.js:252h.Ld @ ima3.js:253Ze @ ima3.js:68h.dispatchEvent @ ima3.js:66im.w @ ima3.js:243We @ ima3.js:63Se @ ima3.js:64(anonymous function) @ ima3.js:62
ima3.js:252 
Uncaught TypeError: Cannot read property 'apply' of undefined

当我用startEvent = 'tap'评论完这条线时,我不再收到这些错误,但video.js播放器的一些功能不起作用,即我无法通过点击视频区域来暂停视频(我需要点击暂停按钮,这在移动设备上很难)。

如何使此"点击"事件在移动设备上正常工作?

我已经更新了videojs ima github上的问题。也许我的解决方案对你来说是可以接受的。

主要问题是,当你点击"播放"按钮时,谷歌ima videojs插件创建的div"ima广告容器"位于videojs播放器上方。

所以我对iPhone设备进行了检测:

jQuery

if (navigator.userAgent.match(/iPhone/i)){
    $('#ima-ad-container').hide().css({'left':'-10000px','top':'-10000px'});
}

Javascript

if (navigator.userAgent.match(/iPhone/i)){
    var imaDom = document.getElementById('#ima-ad-container');
    imaDom.style.display='none';
    imaDom.style.left='-10000px';
    imaDom.style.top='-10000px';
}

一旦videojs-ima插件初始化,您就必须执行此代码,即:

videojs('player').on('adsready', {
   });

我希望它能以某种方式帮助你,它对我起到了作用:)在iPhone 3G、iPhone 3GS、iPhone 4s、iPhone 5&iPhone 6