Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple players with JW Player?

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.

like image 622
fl3x7 Avatar asked Dec 21 '22 14:12

fl3x7


1 Answers

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      
    });
}); 
like image 179
fl3x7 Avatar answered Dec 31 '22 15:12

fl3x7