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

getPlaylistItem().index -> undefined


Hello

I've two problems, both of which are most likely Javascript issues and not JWPlayer issues, but I hope you can nevertheless give me hints.

What I'm trying to achieve is to read the index number of the current item from playlist being played.

In my Javascript I have a global variable for the player

bc.. var videoPlayer;


The init() function is invoked by the onload event of the document and initializes the player (clipInfos is an array with playitems) and a timer invoking the function updateAll is bound to the play state:

bc.. function init() {
videoPlayer = new jwplayer("videoPlayerArea");
videoPlayer.setup({ playlist : clipInfos,
listbar : { position: 'bottom' , size : 120},
events: { onPlay : function() {updateTimerActive = setInterval(updateAll, 1000);},
onPause : function() {clearInterval(updateTimerActive);} }
});
...
}


Up to here everything works as intended.

Now in this function updateAll() I want, besides other things, get the index of the item currently played Listitem and the position.

Therfore I try this:

bc.. function updateAll() {
time=videoplayer.getPosition();
playlistindex=videoplayer.getPlaylistItem().index;
...
}



But this fails in two ways:

1. the reference to the global var videoplayer is not resolved, instead I only get the player position when replacing videoplayer. by jwplayer().

2. after doing so playlistindex=jwplayer().getPlaylistItem().index always returns "undefined"

Any ideas?

Best regards
Markus

44 Community Answers

JW Player

User  
0 rated :

@Makrus

Can you post a link to troubleshoot this?

I use the following on my web site on a couple of examples

bc.. config.playlist[index]



bc.. var config = {
playlist: [
{




having the following at the top of my playlist which is then loaded in the option listing of the JWPlayer as follows:

playlist: config.playlist,


JW Player

User  
0 rated :

Thank you.

I've by now implemented the workaround to save an index with every item when composing the playlist.

Ethan Feldman

JW Player Support Agent  
0 rated :

Oh, glad you got it.

JW Player

User  
0 rated :

For v5 of the player, bc.. jwplayer().getPlaylistItem().index
used to return the playlist index...

I can confirm with v6.3, that bc.. jwplayer().getPlaylistItem().index
indeed returns *undefined*.

When working inside of the bc.. onPlaylistItem
event, the object returned does contain the index reference. However, when anywhere else, I have not found an easy way via the API to determine current playlist item's index.

Is there any particular reason this feature was removed? It was very helpful for the API to be able to return a simple reference to the current playlist position without having to manually track it...

Is a custom workaround the only option?

Ethan Feldman

JW Player Support Agent  
0 rated :

Can I see where you are doing this? Where it is broken?

JW Player

User  
0 rated :

Ethan,

I have also confirmed this behavior in v6.4:

Simply run:
bc.. var item = jwplayer().getPlaylistItem();
console.log(item);
console.log(item.index); // return undefined


...and you'll see that index returns *undefined*. You could run this from longtailvideo.com/jw-player/download/ or any other JW6 player page with a valid playlist. For players containing a single video, you might expect it to return index = 0.

In v5 of the player API, you could easily fetch a reference to the current playlist item via getPlaylistItem(), and the object in the response contained an "index" counter that referenced the position within the playlist array.

To me, this is very useful information and should still be part of the API. Do we know if this was removed intentionally for v6?

Ethan Feldman

JW Player Support Agent  
0 rated :

Can I see where this is running?

JW Player

User  
0 rated :

Ethan,

Yes, can you please see the test URL I emailed you yesterday? I have updated the link to include a working example of the cod I listed above.

Quite simply, the object returned in getPlaylistItem() no longer contains an "index" attribute representing the playlist position.

Ethan Feldman

JW Player Support Agent  
0 rated :

I looked at it and I sent it to Jeroen as well for further debugging.

JW Player

User  
0 rated :

I too am looking for how to get this reference. I'm running the player (6.4) with a playlist and need to be able to grab the current playing item so that I can update DOM elements accordingly. Users may also enter the page and play an item anywhere in the list. Again, I need a way to use getPlaylistItem to grab file, title etc.

Thanks in advance.

JW Player

User  
0 rated :

Ethan,

In case this helps, I found that bc.. jwplayer().getPlaylistItem().index
_worked_ in *v6.0.2813* ...but definitely stopped working in v6.3 and v6.4. I have not tested the versions in between...

JW Player

User  
0 rated :

...I quickly traced through the code, and believe I found the code responsible for setting the "index":

*Excerpt from v6.0.2813*
bc.. _this.getPlaylist = function() {
var playlist = _callInternal('jwGetPlaylist');
if (_this.renderingMode == "flash") {
utils.deepReplaceKeyName(playlist, ["__dot__","__spc__","__dsh__"], ["."," ","-"]);
}
for (var i = 0; i < playlist.length; i++) {
if (!utils.exists(playlist[i].index)) {
playlist[i].index = i;
}
}
return playlist;
};

Ethan Feldman

JW Player Support Agent  
0 rated :

Thanks Mike, I will pass this along as well.

Chris, we are looking into this.

JeroenW

JW Player Support Agent  
0 rated :

Yes, we took that one out as part of a cleanup of our Playlist API. The API did various undocumented things that caused confusion.

This property however was indeed very useful. Instead, for 6.5 (in June), we’ll implement (and document!) a specific getPlaylistIndex() API call to get the index of the currently playing item:

http://developer.longtailvideo.com/trac/ticket/1981

JW Player

User  
0 rated :

Thanks, Jeroen. Looking forward to v6.5, just keeps getting better. Keep up the great work!

JW Player

User  
0 rated :

Jeroen, you mention June for 6.5. Do you have an ETA for when in June? I'm actively involved in a project for which I chose JWPlayer largely because of the documentation saying that this functionality was already there. Now I will be forced to delay much of my development and/or look at another player that can do this.

I appreciate your attention to this!

Thanks
Chris

JeroenW

JW Player Support Agent  
0 rated :

No exact date yet, but first or second week of June…

JW Player

User  
0 rated :

We are also waiting eagerly on this ticket.

JW Player

User  
0 rated :

I am also very interested in this fix asap, as I am trying to obtain the current index, and get the undefined error.

Ethan Feldman

JW Player Support Agent  
0 rated :

We are going to indeed look into it…

JW Player

User  
0 rated :

Any updates on this? I'm also waiting for this fix. Thanks.

Ethan Feldman

JW Player Support Agent  
0 rated :

6.5 should be out soon, it is being tested presently.

JW Player

User  
0 rated :

looks like 6.5 is out now. Has anyone tried this to ensure that it is indeed in there?

JW Player

User  
0 rated :

Ok, I've started testing getPlaylistItem() in the new version. I'm calling jwplayer from jwpsrv.com/library/ so it is the latest version.

I'm trying this:

bc.. var item = jwplayer().getPlaylistItem();
console.log(item);



First time trying it, it gave me:

bc.. Object {description: undefined, file: "http://path/to/the/file", image: undefined, mediaid: undefined, title: "Title of the file"}
description: undefined
file: "http://path/to/the/file"
image: undefined
mediaid: undefined
sources: Array[1]
title: "Title of the file"
tracks: Array[1]
__proto__: Object
player.html:811



Great!!! However, on refresh or loading other movies I get:

bc.. Uncaught TypeError: Cannot read property 'undefined' of undefined NQbASlkTEeK_FSsIACp8akUw.js:65
g.getPlaylistItem NQbASlkTEeK_FSsIACp8akUw.js:65
(anonymous function)



Has anyone else tried this?

If I try

bc.. var playlist = jwplayer().load(playlist);
console.log(playlist);



the console displays

bc.. f.api {container: div#isplayer, id: "isplayer", getBuffer: function, getContainer: function, addButton: function}


Help!!

JW Player

User  
0 rated :

Chris B,

So far I have only played with the new API call on a _single_ video...

bc.. jwplayer().getPlaylistIndex()


It has been successfully returning "0" (which I expected). I have not personally seen any issues related to bc.. getPlaylistItem()
on v6.5 yet like you've mentioned.

I have some time slated for this afternoon to continue testing this with multiple video playlists, and will report back if I experience any similar / new issues....

I'm not sure what you are expecting to be returned from bc.. jwplayer().load(playlist);
, but if you're looking for a reference to the playlist itself, I would try running:

bc.. console.log( jwplayer().getPlaylist() );



JW Player

User  
0 rated :

Hi Mike,

I'm certainly interested in what you find. getPlaylistIndex() returns undefined for me BTW (again, using a multiple video playlist).

I merely referenced jwplayer().load(playlist) to indicate that it is indeed returning what I expect and in fact one of the elements in what it returns is:

bc.. getPlaylistItem: function (a){k.exists(a)||(a=g.getPlaylistIndex());return g.getPlaylist()[a]}

JW Player

User  
0 rated :

Chris,

bc.. getPlaylistIndex()
wasn't introduced until v6.5...

I would recommend upgrading first, confirming both your HTML5 + Flash player / JavaScript mention JW Player 6.5.3609 (or higher).

Once you've confirmed to be running v6.5, I'm curious if the issues you're seeing still exist. However, I'm still not sure _exactly_ what the issue is? Were you expecting something different in the response? Is something specific not functioning as intended?

I don't understand how a page refresh could be changing your use experience, however that does not mean there's still not a bug related to your use of jwplayer().load(). Can you provide any more information about what you're trying to accomplish vs. what is actually happening?

Ethan Feldman

JW Player Support Agent  
0 rated :

@Chris – Can you provide an example of where you tried this?

JW Player

User  
0 rated :

@Ethan, you can test it here: http://learn.infiniteskills.com/test.html

You'll note that I am using a multi video playlist and I have the following code to help with debugging:

bc.. var item = jwplayer().getPlaylistItem();
console.log(item);


Thanks!

Ethan Feldman

JW Player Support Agent  
0 rated :

You are using JW Player 6.2 here.

You need to update to 6.5 – http://account.longtailvideo.com/

JW Player

User  
0 rated :

Hi Ethan,

If I right click on the movie on that page it says "About JW Player 6.5.3609 (Premium Edition)" and I am also using the Cloud hosted version:

bc.. <script src="http://jwpsrv.com/library/NQbASlkTEeK_FSIACp8kUw.js"></script>


Which when viewed also contains this version number:

bc.. ...jwplayer.version="6.5.3609"...


On this page: http://www.longtailvideo.com/support/jw-player/31770/cloud-hosted-vs-self-hosted-jw-player it says that using the Cloud hosted version give you automatic updates to the latest version.

What am I missing?

Ethan Feldman

JW Player Support Agent  
0 rated :

When I right click it is says – “About Infinite Skills”

Your JS is 6.2 – http://www.infiniteskills.com/demos/jwplayer.js

JW Player

User  
0 rated :

My mistake, we're pushing all traffic besides our IP block to the parent site (www.infiniteskills.com). I really need you to see learn.infiniteskills.com. Try this link which I've set up to allow you in:

http://learn.infiniteskills.com/test.html?action=enter

Ethan Feldman

JW Player Support Agent  
0 rated :

Hm, I see this error in Firebug’s console now – NetworkError: 404 Not Found – http://learn.infiniteskills.com/crossdomain.xml

JW Player

User  
0 rated :

Does that have anything to do with this issue? I've added that file there in case it does, but I still have the issue

Ethan Feldman

JW Player Support Agent  
0 rated :

I thought it might be related.

Hm, now I get a different issue – “a is undefined”

JW Player

User  
0 rated :

Yup, that's the issue:

bc.. Uncaught TypeError: Cannot read property 'undefined' of undefined
g.getPlaylistItem
(anonymous function)

JW Player

User  
0 rated :

Ethan, any further thoughts on this? Do you see how getPlaylistItem is not getting defined?

Ethan Feldman

JW Player Support Agent  
0 rated :

Let me have others investigate here.

JeroenW

JW Player Support Agent  
0 rated :

You’re attempting to fetch a playlistItem before the player is actually setup. I’d suggest you call your function only after onReady() or onPlaylist() is fired. That way, the item is always there.

JW Player

User  
0 rated :

@Jeroen

This I understand fully which is similarly to calling a function before it is declared a common mistake often made.

1. Is the order then important as it pertains to the events?

For example:

bc.. events:
{
onTime: timeHandler,
onFullscreen: fullHandler,
onBeforePlay: beforeHandler,
onPlaylistItem: playlistHandler,
onPlay: playHandler,
onPause: pauseHandler,
onComplete: completeHandler
}



I use handler function throughout my JWP6 examples on my web site and see more advantages than disadvantages having them. just love it. ;-)

2. can calls be made to the handler functions?
(ie) timehandler(a,b)

I ask question #2 as I am working on cue points and was successful BUT only for one chapter(values are hard-coded). my video concert page has multiple concerts each with seveal chapters which at the moment work when selected BUT once completed continue to play and understood why.

3. since we are able to use a JSON playlist and have several attribute
bc.. .
.
.
items: {
86: {
thumbnail: 'video/thumbs/yanni1a.png',

},
291.25: {
thumbnail: 'video/thumbs/yanni2.png',
duration: 408
},
.
.
.



Is something like onCue possible with/for future releases of the JWP where as in above the cue(a,b)
namely cue(291.25, 408)?

in the future cue(a,b)
adding to the above listed events
onCue: cuehandler

function cuehandler(a,b)
{

}

I do have a working example but using the timehandler function IF interested, I can send you the the fruit of my efforts; the link.


JeroenW

JW Player Support Agent  
0 rated :

Yes, we are indeed working on a CuePoint API, for the 6.8 version of the player. That release will also enable setting chapter markers in the controlbar. See:

http://developer.longtailvideo.com/trac/ticket/782
http://developer.longtailvideo.com/trac/ticket/1695

Feedback on these specs is welcome! Looks like this is what you’d need.

JW Player

User  
0 rated :

good to hear. as it will certainly help chapters.

I'll shelf this(project) till 6.8 is released

Ethan Feldman

JW Player Support Agent  
0 rated :

Yeah

This question has received the maximum number of answers.