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

onComplete Function With


In javascript the player has a jwplayer().onComplete function which tells the player
to play the next video in the playlist.

When this function is called it seems to load the next video in our playlist but then
immediately fires another onComplete for that video.

Then the player finally loads and starts playing not the next video,
but the video after that.

Ideally we would like the next video in playlist to load and start playing
when a jwplayer().onComplete event is fired.

Any idea what's going wrong?

http://centerlinebeta.net/jw-test/

19 Community Answers

Ethan Feldman

JW Player Support Agent  
0 rated :

This seems to be working for me?

JW Player

User  
0 rated :

So if you scrub the first video to the end ("Why Smarter Storage"), it jumps over the next in line ("Efficient by Design") and starts playing "Self Optimizing" Are you not seeing this?

JW Player

User  
0 rated :

Hi Ethan, I like the new look of jw6, the default skin is cool!
Also it seems to work a lot better on mobile which is great.

I helped write the javascript for the page Ryan mentioned above here:
http://centerlinebeta.net/jw-test/

Overall the videos do play really well.

The main issue we are having as Ryan said is that when you scrub
to the end of a video in our player and let it finish, rather than playing
the next video it skips to the video after next. The core problem
seems to be that the oncomplete even gets fired prematurely.

Can you please take a look at the javascript in link below and confirm
we have setup the jw6 player correctly?
http://centerlinebeta.net/jw-test/lib/js/main.js

Thanks so much!

JW Player

User  
0 rated :

Something comes to mind but not certain; I wonder if this perhaps may be an array issue where an incorrect index is addressed.

As you know arrays start at 0......n where the first video is index[0] and the second vidoe is index[1].

I had a similiar issue that was giving me more grey hair then I need forgetting the length-1 aspect.

just guessing here

Ethan Feldman

JW Player Support Agent  
0 rated :

@Ryan/Andrew – It does not skip over for me, it just plays one after an other.

JW Player

User  
0 rated :

@Ethan It seems to be working as intended in Firefox (OS X 19.0.2)

In Chrome (OS X 26.0.1410.43) and Safari (OS X 6.0.3), it's definitely skipping a video when the current one completes.

What browser(s) are you seeing it work as intended?

Ethan Feldman

JW Player Support Agent  
0 rated :

I checked in Chrome, FF, Win7.

JW Player

User  
0 rated :

again works fine in FF20 released today as well as FF21, 22 ,23

and Chrome 26

Ethan Feldman

JW Player Support Agent  
0 rated :

Yes

JW Player

User  
0 rated :

Definitely isn't working on multiple OS X WebKit browsers both in our office and at our homes. Any ideas on how we can fix/avoid this issue.

I can consistently reproduce it in those browsers, so the question stands are we doing something incorrectly in our JS? Is there something we need to do differently.

Ethan Feldman

JW Player Support Agent  
0 rated :

It might have to do with html5 vs flash modes. Try to set the primary variable to flash, does that help?

JW Player

User  
0 rated :

Hello, I set primary variable to flash, you can see here:
http://centerlinebeta.net/jw-test/

Our issue is solved but for desktop only.

I tested on iPad and we are still having same problem
discussed earlier of videos skipping.







Ethan Feldman

JW Player Support Agent  
0 rated :

Will take a look.

JW Player

User  
0 rated :

Hi Guys

I have been able to reproduce this on Chrome (Mac OS X) and it has proved quite an interesting challenge to resolve!

Basically, the function that is bound to "onComplete" is responsible for "loading" and "playing" the next video in the playlist array - which is does.

However, on Mac OS it appears the "load" and "play" is getting wrapped up in the context of the existing (not-quite-finished) "onComplete" event.

The "load" happens, and then the "play" happens, but the problem is the "play" is actually picking up state from the ever-so-nearly-finished "onComplete" - which means it immediately fires the "onComplete" call again... We go around the loop again. However the next time round the "onComplete" has actually finished (the underlying video "ended" event is fired) and so the play starts from the proper position - the only problem is it's now the wrong video.

The solution:

You need to take the "load" / "play" combo out of the normal event flow so that the "onComplete" can actually complete without interference. This can easily be done by wrapping them in a setTimeout() as follows (_this is in the switchVideo() function_):

bc.. setTimeout(function(){
jwplayer().load({
sources: [
{'file': 'media/'+vid+'.mp4',
'title': 'Power Systems History and Future'},
{'file': 'media/'+vid+'.webm',
'title': 'Power Systems History and Future'}
]}).play();

updateDescription(vidItem);
},0);



That should do the trick.

James

JeroenW

JW Player Support Agent  
0 rated :

Thanks for the explanation and the workaround. We’ll investigate as to why this is going wrong exactly and see how we can fix this.

JW Player

User  
0 rated :

James, u da man!

Your solution worked perfectly.
I tested in Chrome, FF, Safari, IE8, IE9, & iPad.

Also I found I didn't need the primary variable to be flash anymore,
so now we get that html video sweetness.

Thanks!

JW Player

User  
0 rated :

Glad this workaround does the trick, but @JeroenW, can you keep us updated if and when an official fix is found and released? We'd appreciate that!

Ethan Feldman

JW Player Support Agent  
0 rated :

I will send this to Jeroen. Glad you got this sorted though!

JeroenW

JW Player Support Agent  
0 rated :

Yes, we will.

This question has received the maximum number of answers.