JW Player 可以让多个玩家一起玩吗?

发布于 2024-11-03 06:05:32 字数 1121 浏览 0 评论 0原文

尝试用JW Player实现多个播放器。我尝试了几种方法并查看了文档,但我不太确定为什么代码会被破坏。

代码片段如下所示:

In head:

<script type='text/javascript' src='/jwplayer/jwplayer.js'></script>

JS:

    $('video').jwplayer({
        flashplayer: '/jwplayer/player.swf',
        controlbar: 'none',
        stretching: 'fill',
        height: 120,
        width: 120
     });

HTML:

<video  id="video" src="/media/original/original-video.mp4">Loading Video ...</video>

我收到的错误是:

$("video").jwplayer is not a function

现在我认为这是意味着 jwplayer.js 文件没有被加载。然后我读到可能是因为速记 $ 没有被拾取,所以我尝试了 jQuery。没有一个起作用。然而,当我更改 JavaScript 以便它播放单个视频时,例如:

    jwplayer('video').setup({
        flashplayer: '/jwplayer/player.swf',
        controlbar: 'none',
        stretching: 'fill',
        height: 120,
        width: 120
     });

代码实际上有效。然而,这要求我的所有视频标签都具有相同的 ID。我不能这样做,因为我想要多个玩家。

任何帮助将不胜感激。如果有例子就更好了!感谢您的阅读。

Trying to implement multiple players with JW Player. ive tried a few ways and looked at the docs but im not quite sure why the code is breaking.

Code snippets shown below:

In head:

<script type='text/javascript' src='/jwplayer/jwplayer.js'></script>

JS:

    $('video').jwplayer({
        flashplayer: '/jwplayer/player.swf',
        controlbar: 'none',
        stretching: 'fill',
        height: 120,
        width: 120
     });

HTML:

<video  id="video" src="/media/original/original-video.mp4">Loading Video ...</video>

The error I receive is:

$("video").jwplayer is not a function

Now i thought this meant the jwplayer.js file was not being loaded. then i read maybe its because the shorthand $ is not being picked up so i tried jQuery. None worked. However when I change the javascript so that it plays a SINGLE video eg:

    jwplayer('video').setup({
        flashplayer: '/jwplayer/player.swf',
        controlbar: 'none',
        stretching: 'fill',
        height: 120,
        width: 120
     });

The code actually works. However this requires all my video tags to have the same ID. Which I cant do as i want multiple players.

Any help would be really appreciated. An example would be even better! Thanks for reading.

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

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

发布评论

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

评论(1

苦行僧 2024-11-10 06:05:32

我找到了答案。这很简单!只需添加 jQueryeach() 以便每个标签都被初始化:)

希望这对其他人有帮助:

$('video').each(function(){
    jwplayer(this.id).setup({
        flashplayer: '/jwplayer/player.swf',
        controlbar: 'none',
        height: 120,
        width: 120      
    });
}); 

i found the answer. It was a simple one to! just had to add in a jQuery each() so that every tag was initialized :)

Hope this helps someone else:

$('video').each(function(){
    jwplayer(this.id).setup({
        flashplayer: '/jwplayer/player.swf',
        controlbar: 'none',
        height: 120,
        width: 120      
    });
}); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文