Hey guys,
Using v4.1 of the flv media player.
I'm having a problem that I can't seem to figure out. I have my swfobject.js and player.swf on domain A, and I include the js file and swf file on domain B. I am able to get everything working quite easily when everything is on the same domain, but I can't get it working on multiple/remote domains. Also note that I need to dynamically load music, and can't use a predetermined playlist file (which is why I have an 'empty.mp3' in the file flashvar).
test.js located on domainA.com is here:
var playing;
function createPlayer()
{
var s1 = new SWFObject('http://www.domainA.com/mediaplayer.swf', 'mpl', '400', '30', '9');
s1.addVariable('width', '400');
s1.addVariable('height', '30');
s1.addVariable('file', 'empty.mp3');
s1.addVariable('bufferlength', '3');
s1.addVariable('autostart', 'false');
s1.addVariable('showicons', 'false');
s1.addVariable('showstop', 'false');
s1.addVariable('enablejs', 'true');
s1.addVariable('javascriptid', 'mpl');
s1.write('player');
};
function loadSong(song)
{
//if (song != playing) { thisMovie('mpl').loadFile({file:song});}
if (song != playing) { thisMovie('mpl').sendEvent("load", song);}
//thisMovie('mpl').sendEvent('playpause');
thisMovie('mpl').sendEvent('play');
playing = song;
};
function thisMovie(movieName)
{
if(navigator.appName.indexOf('Microsoft') != -1)
{
return window[movieName];
}
else
{
return document[movieName];
}
};
As you can see, the jw player object is also located on domainA.
The html file that includes the above js file and needs to use the sendEvent function is on domainB:
test.html located on domainB.com is here:
<html>
<head>
<title>JW PLAYER TEST</title>
<script type="text/javascript" src="http://www.domainA.com/peekok/test.js?12345"></script>
<script type="text/javascript" src="http://www.domainA.com/peekok/swfobject.js?12345"></script>
</head>
<body onload="createPlayer()">
<div id="player"></div>
<a href="javascript:loadSong('http://www.domainA.com/music/1.mp3'); ">Load Velocity Girl 1</a>
<a href="javascript:loadSong('http://domainA.com/music/Marzipan.mp3'); ">Load Velocity Girl 2</a>
</body>
</html>
So the createPlayer() function in fact creates the player on the page of domainB.com. But when I click on the link to load in a new song, firebug on firefox3 tells me that sendEvent is not a function.
Basically I want to be able to load songs into the player from a remote domain. I control domainA, but I don't control domainB in the average use case.
Thanks for your help!
it is not possible to control a .swf file on another domain for flash security reasons - so you will have to come up with a structure that allows the .swf and the controlling script to be on the same domain (using an iframe maybe?)
or load the file by reinstantiating (recreating) the player instead of using the load command - reinstantiating works crossdomain
just call createPlayer with the filename as argument and set the file flashvar...
please see these demos for example code:
player v.3.x - swfobject 1.5 - http://home5.inet.tele.dk/nyboe/flash/mediaplayer/linkplaylist.htm
player v.4.x - swfobject 2.1 - http://home5.inet.tele.dk/nyboe/flash/mediaplayer4/JW_API_xmpl_3-1-1-1.html
more demos: http://home5.inet.tele.dk/nyboe/flash/