Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Wordpress playlist random play. How to?


Please tell me how to randomize my playlist in wordpress with jwplayer 6 like jwplayer 5.

Thanks in advance.

24 Community Answers

Ethan Feldman

JW Player Support Agent  
1 rated :

You would need to use our API to do this – http://support.jwplayer.com/customer/portal/articles/1413089-javascript-api-reference

onComplete(), play() another entry.

g...

User  
0 rated :

Please, i'm newbie, explain this better, please... i want only randomize playlist when the page loads the player. :D

Ethan Feldman

JW Player Support Agent  
1 rated :

Add this code on your post, under your player. Make sure you are posting in text mode.

<script type="text/javascript"> jwplayer().onReady(function(){ randomItem(); }); function randomItem(){ var playlist = jwplayer().getPlaylist(); var playlistsize = playlist.length; var randomnumber=Math.floor(Math.random()*playlistsize) jwplayer().playlistItem(randomnumber); console.log("Playing item " + randomnumber +"."); }; jwplayer().onComplete(function(){ var playlist = jwplayer().getPlaylist(); var playlistsize = playlist.length; var randomnumber=Math.floor(Math.random()*playlistsize) jwplayer().playlistItem(randomnumber); console.log("Playing item " + randomnumber +"."); }); </script>

g...

User  
0 rated :

Your code is good although it lacks a ";".

But this code causes a problem: the player starts automatically only at the beginning (because, I believe, of "onReady" at the beginning). How do I delete the autostart?

And then, I use wordpress shortcodes with these tags as in the old code jwplayer 5 and everything works as before:

width="100%" loop="true"

There is also a tag for the random feature?

g...

User  
0 rated :

and one more little thing: when you click the Next button, the playlist follows its natural order and not random. How to randomize even the next?

g...

User  
0 rated :

and in case i have more players on my page? and of course i don't know when my own playlist is "0" or "1" or "2"?

Ethan Feldman

JW Player Support Agent  
1 rated :

Here is full code that will not autostart and will also work with the next/previous buttons:

<script type="text/javascript"> jwplayer().onPlaylistItem(function(){ randomItem(); jwplayer().stop(); }); function randomItem(){ var playlist = jwplayer().getPlaylist(); var playlistsize = playlist.length; var randomnumber=Math.floor(Math.random()*playlistsize); jwplayer().playlistItem(randomnumber); }; jwplayer().onComplete(function(){ var playlist = jwplayer().getPlaylist(); var playlistsize = playlist.length; var randomnumber=Math.floor(Math.random()*playlistsize); jwplayer().playlistItem(randomnumber); }); </script>

g...

User  
0 rated :

Now everything works. Only the problem of which player is the player of playlist!

In case i have more players on my page? and of course i don't know when my own playlist is "0" or "1" or "2"?

Ethan Feldman

JW Player Support Agent  
0 rated :

Great, glad it works.

This script is really for one instance at a time.

g...

User  
0 rated :

Oh my god, no, please help me!

I have a blog and on sidebar i have the playlist with this code:

[jwplayer player="2" playlistid="1956" width="100%" loop="true"]

and when users navigate into page with single [jwplayer] in other posts your javascript code above doesn't work anymore!

Please help me.

Ethan Feldman

JW Player Support Agent  
1 rated :

Show me an example and please, calm down.

g...

User  
1 rated :

Ok, sorry.

In a page with a few posts without [jwplayer shortcode] and a sidebar with

[jwplayer player="2" playlistid="1956" width="100%" loop="true"]

everything works fine.

When i go to a page like

/blog/category/music/2/

the wordpress site loads many posts with single [jwplayer shortcodes] (that works!), but my sidebar [jwplayer playlist] doesn't works anymore also i have your javascript code like as in the previous page (the one that has no other jwplayer).

I also noticed that in the first page (where is the alone jwplayer playlist) the id of jwplayer is "0" and in the next page the id is "4".

How to use your code when there are many jwplayer instances?

Ethan Feldman

JW Player Support Agent  
0 rated :

Provide a link please.

g...

User  
0 rated :

I can't. It is in localhost.

Ethan Feldman

JW Player Support Agent  
0 rated :

Can you put something up? That way I can debug it properly.

g...

User  
0 rated :

I can't now, i don't have server.

but it should be simple for you: how to run your splendid javascript code only with one jwplayer of the page when there are so many?

g...

User  
0 rated :

How can i change the id of my jwplayer?

Instead of "jwplayer-0" how can i call my jwplayer "testBeautifulPlayer"?

Ethan Feldman

JW Player Support Agent  
0 rated :

Here is some JS code for this:

<script type="text/javascript"> var maxPlayers = 2; function randomPl(id){ return function(){ var playlist = jwplayer(id).getPlaylist(); var playlistsize = playlist.length; var randomnumber=Math.floor(Math.random()*playlistsize); jwplayer(id).playlistItem(randomnumber); } } function randomPl2(id){ return function(){ var playlist = jwplayer(id).getPlaylist(); var playlistsize = playlist.length; var randomnumber=Math.floor(Math.random()*playlistsize); jwplayer(id).playlistItem(randomnumber); jwplayer(id).stop(); } } for(var i = 0; i < maxPlayers; i++) { var player = jwplayer(i).id; jwplayer(player).onComplete(randomPl(player)); jwplayer(player).onPlaylistItem(randomPl2(player)); } </script>

You just need to pay attention to this line – var maxPlayers = 2;

That is the # of players on your page at the same time. Make it the # of players on your page. It will work.

g...

User  
0 rated :

Ethen you're a great person! Thanks.

But I don't know how many players are at the same time on the same page.

Because the list of posts tomorrow can be 4 players or 1 or zero. It changes every time, every hour!

It would be great if you could name the jwplayer instead of "jwplayer-0", "jwplayer-1", etc... like Wordpress does and i can call them from JavaScript with unique name like "playerBackground".

pity that in jw 5 was all automatic and easy.

Ethan Feldman

JW Player Support Agent  
1 rated :

We can look into adding a shuffle option into the player again.

There isn’t really a way to detect how many instances are on the page automatically though.

g...

User  
0 rated :

How can I know when you add it? Comes an update of the plugin in wordpress?

Can I subscribe me somewhere?

Ethan Feldman

JW Player Support Agent  
0 rated :

Basically, I would need to ask the development team to add this as a configuration option to the player itself. Something like shuffle=true like it was for JW5.

g...

User  
0 rated :

Yes. Essentially i need jw5 but good in HTML5 like jw6.

Ethan Feldman

JW Player Support Agent  
0 rated :

Ok.

This question has received the maximum number of answers.