javascript 使用 JW 播放器在嵌入式视频中禁用播放/暂停

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8829328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:42:39  来源:igfitidea点击:

disabling play/pause in embedded video using JW player

javascriptjwplayervideo-embedding

提问by assassin

I am using JW (v 5.8) player to embed a video. And I want to do it so that autostart is enabled, allowing the video to start playing as soon as the page loads, the controlbar is disabled so that a viewer cannot seek to a random point in a video and the play/pause function on clicking the video is disabled. To embed the mp4 video, I am using JW player. I managed to accomplish the first 2 tasks, but to disable the play/pause function on clicking the screen, I am trying to use the clickproxy plugin and it does not work. I am pasting my code below:

我正在使用 JW (v 5.8) 播放器嵌入视频。我想这样做是为了启用自动启动,允许视频在页面加载后立即开始播放,控制栏被禁用,以便查看者无法寻找视频中的随机点以及点击时的播放/暂停功能视频被禁用。要嵌入 mp4 视频,我使用的是 JW 播放器。我设法完成了前 2 个任务,但要禁用单击屏幕时的播放/暂停功能,我正在尝试使用 clickproxy 插件,但它不起作用。我在下面粘贴我的代码:

<div id="mediaplayer">JW Player goes here</div>

<script type="text/javascript" src="jwplayer.js"></script>
<script type="text/javascript">
    jwplayer('mediaplayer').setup({
        'flashplayer': 'player.swf',
        'file': 'video.mp4',
        'controlbar': 'none',
        'width': '1000',
        'height': '1000',
        'plugins': 'clickproxy',
        'clickproxy.listener': 'clickListener',
        'autostart': 'true'
    });
function clickListener(obj)
{
}
</script>

Right now with this code, the video loads, but doesn't even start playing, and clicking on the video doesn't do anything because of the clickproxy plugin. Anyway to accomplish what I want? I am a newbie in javascript, so any help will be really appreciated!

现在使用此代码,视频加载,但甚至没有开始播放,并且由于 clickproxy 插件,单击视频不会执行任何操作。无论如何要完成我想要的?我是 javascript 的新手,所以任何帮助将不胜感激!

Thanks!

谢谢!

采纳答案by The Coder

Ahhh yes, there used to be functionality in the player to do this (about ignoring the click) but it seems it keeps getting removed.

啊,是的,播放器中曾经有过这样做的功能(关于忽略点击),但它似乎一直被删除。

Here's the solution I've just implemented that works for me, I simply plug into the onPause javascript event and start the media playing again.

这是我刚刚实施的对我有用的解决方案,我只需插入 onPause javascript 事件并再次开始播放媒体。

    <script type='text/javascript'>
  jwplayer('mediaspace').setup({
    'flashplayer': '/jw/player.swf',
    'file': 'http://d3usowdy51yate.cloudfront.net/your-mp4-goes-here.mp4',
    'autostart': 'true',
    'icons': 'true',
    'stretching': 'fill',
    'controlbar': 'none',
    'width': '640',
    'height': '360',
    events: {
        onPause: function(event) {
          jwplayer('mediaspace').play();}
    }
  });
</script>

回答by TheWiseG

Try to put a transparent div over the player with the same dimension of the player.

尝试在播放器上放置一个与播放器尺寸相同的透明 div。

回答by Sindre Sorhus

You can use the CSS property pointer-events on the #mediaplayerto prevent the click event to go trough to the video:

您可以使用 CSS 属性 pointer-events#mediaplayer来防止点击事件进入视频:

#mediaplayer {
    pointer-events: none;
}

You could also abuse the onPauseevent as a fallback for older browsers <IE9, by saying; play the video if the pause event is executed:

你也可以滥用这个onPause事件作为旧浏览器的后备<IE9,说;如果执行暂停事件,则播放视频:

jwplayer('mediaplayer').setup({
    flashplayer: 'player.swf',
    file: 'video.mp4',
    controlbar: 'none',
    width: '1000',
    height: '1000',
    autostart: 'true',
    events: {
        onPause: function() {
            this.play(true);
        }
    }
});