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

jw6: crossdomain error when attempt to load youtube video


I am attempting to migrate from jw5 to jw6. With jw5, I have no problem playing youtube videos. With jw6, I am able to load a youtube video if it is loaded at the same time the jwplayer is created. But when I attempt to load a youtube video after the player has been created, I get a crossdomain error: "Playlist could not be loaded: Crossdomain loading denied".

Here is the script. Note that the video "youtube1" successfully loads during setup, and the video "youtube2" fails to load when the user clicks on the box.

bc.. <style>
#box{
width: 50px;
height: 50px;
background-color: #FFFF66;
}
</style>
<body>
<div id='content'>
<div id='container'></div>
<div id='box'></div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
var youtube1 = 'https://www.youtube.com/watch?v=fljKx9nvrL4';
var youtube2 = 'https://www.youtube.com/watch?v=S3OJOGxy21k';
var myflashplayer = './jwplayer.flash.swf';
var params = {height: 200, width: 300, file: youtube1, flashplayer: myflashplayer};
var myplayer = jwplayer('container').setup(params);
$('#box').click(function() {
myplayer.load(youtube2);
});

});
</script>





14 Community Answers

Ethan Feldman

JW Player Support Agent  
0 rated :

Do you have a link?

JW Player

User  
0 rated :

here is a link:
http://manylights.info/debug/jw6.html

Ethan Feldman

JW Player Support Agent  
0 rated :

Try to use:

var params = {height: 200, width: 300, file: youtube1, primary: "flash"};

JW Player

User  
0 rated :

When I use the params you suggested, I get the same error message: "Playlist could not be loaded: crossdomain loading denied".

Ethan Feldman

JW Player Support Agent  
0 rated :

Maybe it has to do with how you are loading the player? What if you just do a basic setup, no jquery? To test, that is.

JW Player

User  
0 rated :

I'm not sure what you mean by a "basic setup, no jquery". Are you saying I shouldn't use the javascript api to create the player? How exactly would you like me to create the player? Thanks.

Ethan Feldman

JW Player Support Agent  
0 rated :

I just want you to do a quick, basic set up, like this – http://www.longtailvideo.com/support/jw-player/28833/quick-start-guide

JW Player

User  
0 rated :

I believe the "crossdomain" error was a red herring. I was using the wrong syntax and should have been calling:

bc.. myplayer.load({file: youtube2})



rather than

bc.. myplayer.load(youtube2).



At least that was the syntax that worked for jw5.

The bigger problem now is that myplayer.load() does not seem to work in jw6.

I filed a separate issue here:
http://www.longtailvideo.com/support/forums/jw-player/javascript-interaction/30385/jw6-how-to-dynamically-load-file-using-javascript-api

JW Player

User  
0 rated :

Also, just to clarify ...

The problem I was having was not with the player setup. That worked fine. I was able to setup the player and have it load a video.

bc.. var youtube1 = 'https://www.youtube.com/watch?v=fljKx9nvrL4';
var myflashplayer = './jwplayer.flash.swf';
var params = {height: 200, width: 300, file: youtube1, flashplayer: myflashplayer};
var myplayer = jwplayer('container').setup(params);



The problem I was having (and continue to have) is that I cannot dynamically load a different video, after the player had been setup.

bc.. var youtube2 = 'https://www.youtube.com/watch?v=S3OJOGxy21k';
$('#box').click(function() {
myplayer.load({file: youtube2});
});

Ethan Feldman

JW Player Support Agent  
0 rated :

Ok, glad you got that.

For the 2nd issue, it seems to work for me, I just did this test:

<!DOCTYPE html>
<script src="jwplayer.js"></script>
<center><div id='my-video'></div></center>
<script type='text/javascript'>
    jwplayer('my-video').setup({
        file: 'http://www.youtube.com/watch?v=xSE9Qk9wkig',
        width: '580',
        height: '370'
    });
</script>

<br />
<center><a href="#" onclick="var youtubeVideo='http://www.youtube.com/watch?v=AS1UJ8J3Yq8'; jwplayer().load({file: youtubeVideo});jwplayer().play();">Load a YouTube Video!</a></center>

JW Player

User  
0 rated :

Thanks very much. bc.. myplayer.load({file: youtubeVideo})
is working for me now.

I have run into another problem, though.

If I load a youtube video during player setup, and then load a different youtube video (for example in response to a user click), it all works.

Similarly, if I load a video from my local server during player setup, and then load a different local file (for example in response to a user click), it all works.

However ...

If I load a youtube video during player setup, and then try to load a local file (for example in response to a user click), I get this error message:

bc.. Error loading youtube: video ID is invalid



Is it possible, in jw6, to load the player with a local video file, if the player was originally loaded with a youtube video during setup? I believe this was possible in jw5.


Ethan Feldman

JW Player Support Agent  
0 rated :

Np.

I checked this and it looks like it isn’t possible. The only way to do this would be to have an entire new setup() passed in via the onclick, instead of load()

JW Player

User  
0 rated :

Oh, that's too bad.

Do you know if there are any plans to extend the current jw6 player functionality, so that the same player can play both youtube videos and local video files?

Ethan Feldman

JW Player Support Agent  
0 rated :

I can ask.

This question has received the maximum number of answers.