OGeek|极客世界-中国程序员成长平台

标题: ios - 在 iPhone 原生播放器上避免可搜索和可跳过的 html5 视频广告 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:52
标题: ios - 在 iPhone 原生播放器上避免可搜索和可跳过的 html5 视频广告

我设置了一个 HTML5 播放器(使用 video.js),它在视频本身之前播放和广告视频。

问题出现在 iPhone 设备上,当 Safari 调用原生 iOS 播放器通过搜索控件播放视频时,用户可以轻松跳过广告。

check this out

我已将属性“playisinline”和“webkit-playisinline”应用到标签中,这仅在 iOS 10 上有效(顺便说一句,您可以在下次更新时本地应用它),但在 iOS 9 上它仍然向本土玩家展示寻求可能性。

我尝试使用 this正如其他地方所建议的那样,但它非常有问题并且在我的播放器实现中产生冲突。

我只需要控制全屏 native 播放器并通过将当前播放时间重置为该播放器来避免搜索,但我找不到如何做到这一点。

任何帮助表示赞赏。



Best Answer-推荐答案


您是否尝试过以下代码段?它将阻止向前搜索。

这个想法很简单,每秒使用一个间隔来抓取当前位置。如果搜索位置大于当前位置,则将其设置回去。这只是一种解决方法

if (document.getElementById("vid1")) {
  videojs("vid1").ready(function() {
    
    var myPlayer = this;

    //Set initial time to 0
    var currentTime = 0;
    
    //This example allows users to seek backwards but not forwards.
    //To disable all seeking replace the if statements from the next
    //two functions with myPlayer.currentTime(currentTime);

    myPlayer.on("seeking", function(event) {
      if (currentTime < myPlayer.currentTime()) {
        myPlayer.currentTime(currentTime);
      }
    });

    myPlayer.on("seeked", function(event) {
      if (currentTime < myPlayer.currentTime()) {
        myPlayer.currentTime(currentTime);
      }
    });

    setInterval(function() {
      if (!myPlayer.paused()) {
        currentTime = myPlayer.currentTime();
      }
    }, 1000);

  });
}
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet"/>
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<video id="vid1" src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" controls class="video-js vjs-default-skin vjs-big-play-centered" width="640" height="360" preload="auto"></video>

关于ios - 在 iPhone 原生播放器上避免可搜索和可跳过的 html5 视频广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108957/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4