问题描述
在我的项目中,我使用 YouTube 视频嵌入(不是我的视频),我希望它们不显示广告。
当我使用 Iframe 嵌入(没有 Iframe API - 使用 youtube-nocookie.com)时,它可以工作,但不显示广告,这是我想要的。
<iframe id="video" src="https://www.youtube-nocookie.com/embed/7TXKBlBBbIA?fs=0&modestbranding=1&playsinline=1&rel=0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" width="640" height="360" frameborder="0"></iframe>
但是当我使用 Iframe API(通过 youtube-nocookie.com)时,会显示我不想要的广告。
https://developers.google.com/youtube/iframe_api_reference
// HTML
<div id="video"></div>
// JS
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag,firstScriptTag);
function onYouTubeIframeAPIReady() {
video = new YT.Player('video',{
height: 360,width: 640,videoId: '7TXKBlBBbIA',host: 'https://www.youtube-nocookie.com',playerVars: {
'fs': 0,'modestbranding': 1,'playsinline': 1,'rel': 0
}
});
}
问题是,我需要使用 Iframe API,而不是展示广告。有什么方法可以实现吗?
似乎 https://listenonrepeat.com/
是这样做的,但我不知道他们是如何做到的。
解决方法
在嵌入视频中开启或关闭广告
如果您已关联您的 YouTube 和 AdSense 帐户并允许嵌入视频,您将自动选择展示广告。请注意,嵌入的视频将采用与 youtube.com 上的视频相同的广告启用设置。
如果您不想在嵌入的视频中展示广告,则无法仅直接在嵌入的视频中关闭广告。您可以完全关闭嵌入。
正如您所提到的,https://listenonrepeat.com/ 的开发人员可能会从内容创建者那里获得权利并将这些视频上传到他们的频道,或者也可能 https://listenonrepeat.com/ 播放的所有视频} 不由内容创建者获利。