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

Play by filename for file in playlist


Hi

Is it still possible to play the video by filename instead of playlist item?
I have created a click-able link to directly play the item in the playlist, but I will need to re create it (200 videos) whenever I add a new video.
I found a solution from this website,wondering whether its usable before i hire someone to code it for my.
Thanks!

http://jinsungpsu.com/?p=599


JW Player, Play playlist item by filename, rather than index

Problem:

I have a playlist of 45 items that will be played via javascript throughout one page (it’s a glossary page with audio files). I found myself repeatedly making mistakes on which index belongs to what word. As it stands, you would have to remember that the 40th item belongs to a specific word and play it by using jwplayer(‘playerID’).playlistItem(39). What happens if I insert an item on the playlist? I either have to put it at the end, putting things out of alphabetical order, or have to go back and change all the index references in the page.

Solution:

When the page is loaded, I go through the entire playlist once and create a key/value object with the filename and index. Now I can play the items by name. Instead of jwplayer(‘playerID’).playlistItem(39), it will be a much more readable playItemByName(‘the40thitem.mp3′). This will be MUCH more easier to debug and maintain.

This could easily be modified to play using the title or description instead.

The code:

// Go through the playlist and create a key/value pair array so that we can assign playlist index numbers (since jw player can only reference playlist items by index, not name)
var playlistIndices = new Array();
$(document).ready(function() {
var i = 0;
for (i=0; i<glossaryPlaylistItems.length; i++) {
var path = glossaryPlaylistItems[i].file.split(‘/’); // split up the path by ‘/’ for next step
path = path[path.length-1]; // get the filename, lose the folder reference part
playlistIndices[path]=i;
}
});

function playItemByName(itemName) {
jwplayer(‘glossaryPlaylist’).playlistItem(playlistIndices[itemName]);
}


1 Community Answers

jherrieven

User  
0 rated :

Yes, the principle is sound.

I personally would use "mediaid" instead of file name - but that assumes you've added a mediaid parameter to each playlist item. This would then overcome the issue where the item is not using just a single file (in the case where you have multiple variants or quality levels).

Depending on presentation nature of the links, you could just build these dynamically on the fly when the playlist has loaded.

James Herrieven

This question has received the maximum number of answers.