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

JW 7 and AMD / define


when including the jw javascript file, it is looking for the presence of the the 'define' function a the window scope and then chooses to load jwplayer with the define function. When it does this, jwplayer function isn't available in the window scope. Im not sure how to get a handle to the jwplayer object anymore. Has anybody else experienced this?

10 Community Answers

Todd

JW Player Support Agent  
0 rated :

Can you send us a link to your page so we can investigate further?

josh

User  
0 rated :

I can't anymore with the player on it because we had to take it off. However the website is eatthis.com

josh

User  
0 rated :

a specific page would be the following
http://www.eatthis.com/tilapia-is-worse-than-bacon

this part of the jw7 (platform) script that gets included is the part that is doing it

"object" == typeof exports && "object" == typeof module ? module.exports = b() : "function" == typeof define && define.amd ? define(b) : "object" == typeof exports ? exports.jwplayer = b() : a.jwplayer = b()

if i strip out everything but the very last bit 'a.jwplayer = b()' it runs like a charm

a further complication for me is that we are just an ad partner of the site. we deliver an ad unit that uses jw video ads. we noticed this incompatibility on just this one site, I think its because the site is an angular app using AMD modules

Todd

JW Player Support Agent  
0 rated :

Thanks for sending this. AMD and Angular are a bit over my head, but my suggestion would be to potentially avoid any Javascript conflicts by loading your player and ad in an <iframe> instead.

I’ll have one of the engineers take a look at this page and get back to you.

And I should have read this article sooner, since I had tilapia for dinner the other night…

cameron

User  
0 rated :

I believe I am having the same (or at least very similar issue) with JWPlatform. I am using Require.JS to load one of the embed files like this:
require(["http://content.jwplatform.com/players/***-***.js"]);
// video and player ids removed

Immediately after this, I receive the JS error: Uncaught ReferenceError: jwplayer is not defined
Line 18 of the js file returns the error, this line contains:
jwplayer.key = "***";
// Key removed

In this case, I'm sure I'm hitting the "define(b)" part of the if statement, as I traced it using the debugger.

This appears to me, that the way your define is used in the jwplatform files, does not also set:
window.jwplayer = b();

I am not attempting to hijack this thread, I believe these are the same issues, but let me know if I should move this to a different thread.

Thanks!

cameron

User  
1 rated :

Sorry, one addition.... if I do a minor code change to say, instead of:
define(b)

put:
function(){a.jwplayer = b(); define(b)}()

it works properly, as expected. I realize that this is not a great piece of code... but unfortunately, it seems like the structure of this code in jwplatform is really not correct, since it's defining something that subsequently is never used in a "require([...])" statement (since it's all within the same file).

matthew.brennan

User  
0 rated :

This is proper issue. I'm trying to upgrade from jw6 to jw7 and we use require JS and have the same problem.

The jwplayer window variable is not being exported properly. Even using a shim with require.js doesn't help. jw6 worked fine with require.js but as it stands jw7 will not work.

ap

User  
0 rated :

Yep same issue here, I just fixed it by making sure it didn't find the proper variables,[export, module, define] so it attached it to the global namespace. It would be nice if there was a way to not have to modify your source code.

Any updates on this issue?

seb

User  
0 rated :

Hi guys,

any update on this one? we are experiencing the same issue with requirejs .it is blocking our migration for 6 to 7 too.
did anyone find any workaround for this ?

thanks!
-seb

dkierans Kierans

User  
0 rated :

i confirm ap's workarround worked for me, if you put
window.exports = undefined;
window.define = undefined;
window.module = undefined;

at the begining of your jwplayer.js then jwplayer works ok

require(['//youserver.com/jwplayer-self-hosted.js'], function () {
console.log(window.jwplayer )
}
it forces you to move to self hosted thought

This question has received the maximum number of answers.