使用 JW 播放器禁用嵌入式视频的播放/暂停

发布于 2024-12-26 07:25:02 字数 868 浏览 4 评论 0 原文

我正在使用 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>

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

谢谢!

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:

<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!

Thanks!

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

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

发布评论

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

评论(3

徒留西风 2025-01-02 07:25:02

啊,是的,播放器中曾经有一个功能可以做到这一点(关于忽略点击),但它似乎不断被删除。

这是我刚刚实现的适合我的解决方案,我只需插入 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>

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.

    <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>
一场春暖 2025-01-02 07:25:02

您可以使用 #mediaplayer 上的 CSS 属性指针事件来防止点击事件进入视频:

#mediaplayer {
    pointer-events: none;
}

您还可以滥用 onPause 事件作为后备较旧的浏览器,通过说;如果执行暂停事件则播放视频:

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

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

#mediaplayer {
    pointer-events: none;
}

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

jwplayer('mediaplayer').setup({
    flashplayer: 'player.swf',
    file: 'video.mp4',
    controlbar: 'none',
    width: '1000',
    height: '1000',
    autostart: 'true',
    events: {
        onPause: function() {
            this.play(true);
        }
    }
});
小猫一只 2025-01-02 07:25:02

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

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

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