使用 IMA SDK 时,有两个单独的视频播放器,即内容视频播放器和广告播放器。SDK 会自动管理将广告播放器叠加在内容视频播放器上。因此,直接向视频播放器添加事件监听器是行不通的。一种解决方法是显示和隐藏广告容器,但这可能会干扰 SDK 功能。更好的解决方案是将两个玩家封装在父 div 中,并将事件监听器附加到该父 div。本指南将介绍具体方法。
前提条件
集成了 IMA HTML5 SDK 的 HTML5 视频播放器。如果您还没有 IMA SDK,请参阅设置 IMA SDK。
修改 HTML
首先,您需要更改 HTML 以添加一个同时封装广告播放器和内容视频播放器的 div。在“设置 IMA SDK”中,系统已使用 mainContainer 为您完成此操作:
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-06-24。"],[[["The IMA SDK uses two separate video players: one for content and one for ads, which it automatically overlays."],["Directly adding event listeners to the content video player is ineffective due to the ad overlay."],["Wrap both video players in a parent `div` and attach event listeners to that parent element for proper functionality."],["This method enables event handling (like click detection) on the video, irrespective of ad playback, while preserving ad click-throughs."]]],[]]