Multiple players with JW Player?

Trying to implement multiple players with JW Player. ive tried several ways and looked at the docs, but I'm not quite sure why the code is breaking.

The following are snippets of code:

In the 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 am getting is:

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

Now I thought this meant that the jwplayer.js file was not loading. then I read, perhaps this is because the $ transcript is not matched, so I tried jQuery. No one worked. However, when I modify javascript so that it plays a single video, for example:

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

The code really works. However, this requires that all of my video tags have the same identifier. Which I can’t do, because I want several players.

Any help would be really appreciated. An example will be even better! Thank you for reading.

+4
source share
1 answer

I found the answer. It was easy! just needed to add each () to jQuery so that each 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 }); }); 
+11
source

All Articles