HTML5 视频播放器阻止搜索

发布于 2024-09-29 01:21:49 字数 165 浏览 0 评论 0原文

我正在创建一系列视频教程,并希望防止用户向前查找和跳过部分。我将使用将用于桌面和 iPad 浏览器的 HTML5 视频播放器。理想情况下,我希望它也能在 iPhone 上运行,但我意识到你无法控制手机上的视频,因为它使用 iPhone 视频播放器。

如何防止用户在 HTML5 视频播放器上向前搜索?

I'm creating a series of video tutorials and would like to prevent users from seeking forward and skipping sections. I'll be using an HTML5 video player that will be used for desktop and iPad browsers. Ideally, I'd like this to work on the iPhone as well, but I realize you have no control over the video on the phone since it uses the iPhone video player.

How can I prevent users from seeking forward on an HTML5 video player?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦一生花开无言 2024-10-06 01:21:50

谢谢你的回答,瑞克。

我注意到用户可以拖动并按住搜索器,这允许他们继续,因此我将不搜索的位置添加到 getPos 函数。HTML 5 和 jQuery。

var video = document.getElementsByTagName('video')[0];

function allowMove() {
  $('input[id$="btnNext"]').removeAttr('disabled');
  $('input[id$="videoFlag"]').val("1");
}

function getpos() {
  if (!(video.seeking)) {
    curpos = video.currentTime;
  }
  console.log(curpos)
}
onesecond = setInterval('getpos()', 1000);

function setPos() {
  var ct = video.currentTime;
  if (ct > curpos) {
    video.currentTime = curpos;
  }
}

Thanks for your answer Rick.

I noticed that the user can drag and hold the seeker which allowed them to continue so I added where not seeking to the getPos function.HTML 5 and jQuery.

var video = document.getElementsByTagName('video')[0];

function allowMove() {
  $('input[id$="btnNext"]').removeAttr('disabled');
  $('input[id$="videoFlag"]').val("1");
}

function getpos() {
  if (!(video.seeking)) {
    curpos = video.currentTime;
  }
  console.log(curpos)
}
onesecond = setInterval('getpos()', 1000);

function setPos() {
  var ct = video.currentTime;
  if (ct > curpos) {
    video.currentTime = curpos;
  }
}

甚是思念 2024-10-06 01:21:50

如果您真的想做这种对用户不利的事情,那么您可以使用 控制属性。您必须使用 JS 来实现您希望允许的任何控件。

当然,用户始终可以查看> source 获取视频的 URI 并下载它。

If you really want to do this amazingly user-hostile thing, then you can make use of the controls attribute. You will have to implement any controls you do want to allow using JS.

Of course, the user can always just view > source to get the URI of the video and download it.

鹊巢 2024-10-06 01:21:50

为什么不这样呢?

var video = document.getElementById("myVideo");
var counter = 0;

video.on('timeupdate', function() {
  if (video[0].paused == false) {
    counter = video[0].currentTime;
  }
}

video.on('seeking', function(e) {
  if ( parseInt(counter, 10) != parseInt(video[0].currentTime, 10) ) {
    video[0].currentTime = counter;
  }
});

Why not this way?

var video = document.getElementById("myVideo");
var counter = 0;

video.on('timeupdate', function() {
  if (video[0].paused == false) {
    counter = video[0].currentTime;
  }
}

video.on('seeking', function(e) {
  if ( parseInt(counter, 10) != parseInt(video[0].currentTime, 10) ) {
    video[0].currentTime = counter;
  }
});
并安 2024-10-06 01:21:50

我同意 @Bart Kiers 的观​​点,这不是一个好主意,但如果你必须这样做,我可以想到一种方法:隐藏控件并提供你自己的播放按钮,使用 JavaScript 启动视频。

I agree with @Bart Kiers that this is not a very good idea, but if you must do it, I can think of one way: hide the controls and provide your own play button that starts the video using JavaScript.

花心好男孩 2024-10-06 01:21:49

Video.js 的另一个示例:

videojs('example_video_1').ready(function(){
  var player = this;
  var previousTime = 0;
  var currentTime = 0;
  var seekStart = null;

  player.on('timeupdate', function(){
    previousTime = currentTime;
    currentTime = player.currentTime();
  });

  player.on('seeking', function(){
    if(seekStart === null) {
      seekStart = previousTime;
    }
  });

  player.on('seeked', function() {
    if(currentTime > seekStart) {
      player.currentTime(seekStart);
    }
    seekStart = null;
  });
});

Another example for Video.js:

videojs('example_video_1').ready(function(){
  var player = this;
  var previousTime = 0;
  var currentTime = 0;
  var seekStart = null;

  player.on('timeupdate', function(){
    previousTime = currentTime;
    currentTime = player.currentTime();
  });

  player.on('seeking', function(){
    if(seekStart === null) {
      seekStart = previousTime;
    }
  });

  player.on('seeked', function() {
    if(currentTime > seekStart) {
      player.currentTime(seekStart);
    }
    seekStart = null;
  });
});
简单爱 2024-10-06 01:21:49

我只是想阻止向前寻找。我的系统中有更多代码,允许他们暂停并稍后返回。它记录当前位置并设置加载时的视频位置。

我正在使用 video.js。我尝试使用 timechange 事件,但它在查找之前触发。所以,我采取了利用间隔来每秒抓取当前位置。如果查找位置大于当前位置,则将其设置回来。效果很好。

var player = null;
var curpos = 0;
videojs('player').ready(function(){
  player = this;
});

player.on('seeking', function () {
  var ct = player.currentTime();
if(ct > curpos) {
  player.currentTime(curpos);
}
});

function getpos() {
  curpos = player.currentTime();
}
onesecond = setInterval(getpos, 1000);

I only wanted to prevent seeking forward. I have more code in my system that allows them to pause and come back later. It records the current position and sets the video position on load.

I'm using video.js. I tried to use the timechange event, but it fires before seeking. So, I resorted to using an interval to grab the current position every second. If the seeking position is greater than the current position, then set it back. Works great.

var player = null;
var curpos = 0;
videojs('player').ready(function(){
  player = this;
});

player.on('seeking', function () {
  var ct = player.currentTime();
if(ct > curpos) {
  player.currentTime(curpos);
}
});

function getpos() {
  curpos = player.currentTime();
}
onesecond = setInterval(getpos, 1000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文