Go
Not registered? Sign up!

sendEvent not a function when swfobject is remote

Google Translate
24 posts | return to the JavaScript Interaction forum | get the rss feed for this thread

Sep. 18, 2008gstar

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!

Sep. 18, 2008andersen

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/

Sep. 18, 2008gstar

Thanks Andersen.

So it's not going to be possible to use an iframe in my particular case, unfortunately. I can re-instantiate the player, but I need the user to be able to pause the playback. I'll be making the player invisible (height and width will be 0), so is there any way to control play/pause in this case from a link??

I was reading something about the crossdomain security file. Does this type of file, which gives some permissions for cross domain control, work in this case?

Good to know that re-instantiation will work. I'll try that...

Sep. 18, 2008kLink

I could be wrong, but let me throw this out.

I think this is more of a Cross-Site Scripting (XSS) issue than a Flash Player cross-domain issue.

The cross-domain security prevents loading of data files from a domain other than the domain that the movie came from, unless you have a cross-domain policy file on the domain that is serving the data files.

In this case, I think you are trying to execute JavaScript that came from a domain other than the domain that served the original HTML document. That makes it XSS. The browsers all sandbox JavaScript, making it impossible to do this. You can change some settings in Firefox to allow this, but realistically, your users aren't going to be changing their security settings.

my 2¢ grin

Sep. 18, 2008gstar

I can play/pause with the player controls when instantiated, but when the player is hidden (width and height are 0), is there any way for me to control the play/pause? sendEvent doesn't work because the player is remote, but I'm guessing that since I can control play/pause on the player I should be able to do it through a command of some sort (??).

Sep. 18, 2008kLink

I think you can make the player almost hidden (wdith & height = 1) and still control it. The other option is to move the player off of the page with an HTML element position change of -500px making it not visible, but still controllable. I've done this to make the "flash" of re-instantiating the player less annoying.

-500
re-instantiate
500

Sep. 18, 2008gstar

kLink the problem is that sendEvent doesn't work when the player source is on another domain. Andersen gave a solution to re-instantiate the player, but that still doesn't solve the problem of play/pause.

Any ideas?

Sep. 18, 2008kLink

Sorry, I mis-understood a bit.

No you can't control the player through the JavaScript API if it comes from another domain. The JavaScript is sandboxed by the browser.

I thought you were trying to re-instantiate the player with autostart set true or false as a way of controlling the player.

Let's go back to your basic premise for a moment...

You control domain-A which has player.swf and test.js.

You load the player.swf and test.js in an HTML page coming from domain-B.

Because the player.swf and the test.js came from domain-A, the browser with the HTML loaded from domain-B can't control the player through the JavaScript API.

There are only two ways that I know of that work:

1) Use an iframe, which you said that you couldn't do,

2) load the player.swf and test.js from domain-A through a proxy script on domain-B, so it looks like they came from domain-B.

Otherwise, you're sandboxed or have to resort to kludgy methods like re-instantiating the player to change the settings.

Sep. 18, 2008gstar

So I guess the only thing I can do is instantiate the player to start. re-instantiate with a dummy file to stop. re-instantiate with a real file to start again...

ya, that's pretty bad...I think it makes sense to try to do an iframe.

Sep. 18, 2008gstar

One final question for you guys. While I'm not able to use sendEvent to control the remote player, can I receive events from the player? I need to get a notification when the song is finished playing. Is this possible?

Sep. 18, 2008kLink

I've never tried just receiving calls cross-site. It would be a lot of work to setup, and my guess is that it wouldn't work, so I'm not gonna waste time trying.

However, I have a couple of applications that have been festering for a while that need cross-site "something" and I have just run across a JavaScript/Flash application that might make that "something" possible. One of the applications is getting YouTube URIs purely with Javascript, on the client only. No serverside scripts.

Take a look at: http://flxhr.flensed.com/

I haven't used it yet, but the mention of "cross-domain-communication" caught my attention.

Sep. 19, 2008gstar

Update: I found out you can "skin" the player, so I'm looking into doing that. Thanks for all your help!


Thanks for all your help kLink and Anderson.

I've tried to figure out alternatives for doing what I need done. Right now I'm using a "play" button graphic and a "stop" button graphic, which correspond to a "create" and "destroy". The problem is when the song ends, I have no way to know and therefore can't go back to the "play" button graphic. This is a cosmetic problem for the user, but still a major issue.

So I'm starting to think of another possible scenario. Can I only show the play button of the jw player? I don't want to see volume control, the timeline progress, or anything else. I just want the play button. Is this possible??

Thanks again.

Oct. 22, 2008 semsvuj

hi
while i am using this code i am getting 'object doesn't support this property or method' error

var obj2 = {type:"video",file:"http://www.myserver.com/othervideo.flv",title:"Someone else's Cool Video"};
var lst = Array(obj,obj2);
player.sendEvent("LOAD",lst);

the video is playing well and i able to stop them.
but when i want to chage the file it doesn't work
plz help me

Oct. 22, 2008kLink

 
@semsvuj,

Do you have valid code to get the player reference object?

We might be able to help you if you post your full player code.

I never could get the multiple object loading method to work. See this post for a method that does work: http://www.jeroenwijering.com/?thread=11853#msg77102

Dec. 01, 2008Prince

I'm trying to re-play a flash object by clicking a link.

lets say "flash_player" is an object. I'm using flash_player.play();

it works in IE7 but not in Firefox. It says, flash_player.play() is not a function.

is there any quick solution.

thanks in advance.

Dec. 01, 2008andersen

@Prince - the syntax in the v.4.x player is - flash_player.sendEvent("PLAY");

for v.4.x player source code examples please see - http://www.jeroenwijering.com/?item=Javascript_API_Examples
for v.3.x player examples - http://home5.inet.tele.dk/nyboe/flash/

all flashvars and javascript api commands - http://code.jeroenwijering.com/trac/

Dec. 02, 2008Prince

Thanks Andersen..

My limited knowledge in flash could not fix the problem. Its showing similar problem with sendEvent("PLAY");

Here is what i've done.


<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
width="490" height="409" id="t_animation" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/img/flash/mgnt.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="/img/flash/mgnt.swf" quality="high" bgcolor="#ffffff" width="490"
height="409" name="t_animation" align="middle" allowScriptAccess="always" enablejavascript="true"
type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>



AND In javascript part...



function playFlash() {
flash_player = document.getElementById('t_animation');
flash_player.sendEvent('play');
}



And To call this player


<a href="javascript:void(0)" onClick="playFlash()">Click here to see the effect on all</a>


It goes upto half automatically. and when clicking on the link rest of the animation plays. It works in IE but not in Firefox.

Can you please suggest what I've done wrong here. I've spend a bit time in it but can't make it work with my limited knowledge of flash.

Your help would be appreciated.

cheers
Prince

Dec. 02, 2008kLink

Firefox needs to have a name attribute in the object element.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
width="490" height="409" id="t_animation" name="t_animation" align="middle">


The event name has to be all uppercase. Sending PLAY without a boolean will toggle the player's state.
flash_player.sendEvent('PLAY'); // toggles the player's state
flash_player.sendEvent('PLAY', 'true'); // starts the player
flash_player.sendEvent('PLAY', 'false'); // pauses the player

Dec. 02, 2008Prince

Thanks kLink,

Sorry to be pain here.

when i do flash_player.sendEvent('PLAY'); it doesn't do work in IE and firefox both where firefox says "sendEvent is not a function".

when i used flash_player.play(), it did work on IE 7 but in firefox, it said, play is not a function.

(i added the name attribute as well).

Do you think, i can do anything further?

cheers.
Prince

Dec. 02, 2008andersen

what version of JW FLV Media Player do you have ? (on windows a right click on the player will show)

also make sure your flash browser plugin is up to date -
please note that IE and the other browsers doesnt use the same - so check in each -
and note that sometimes a deinstall is needed for the update to function properly...

adobe flash versiontest - http://www.adobe.com/products/flash/about/
adobe flash deinstall - http://kb.adobe.com/go/tn_14157
adobe flash install - http://www.adobe.com/go/getflashplayer

are there any particular reason why you use the object/embed code ?
- it is a lot easier to embed using the swfobject - it rarely fails - except in some inferior CMSystems or social websites that doesnt permit the use of javascript - and as you are using javascript anyhow, that doesnt seem to be the case...
but note that sometimes such systems will rewrite your code without notifying !

please see the page - http://www.jeroenwijering.com/?item=Javascript_API_Examples
it also shows an example of the full object/embed code - but in particular links to many copy/paste examples
note though that these examples all use the swfobject v.2.1 - http://code.google.com/p/swfobject/
at the time of writing the .zip download from - http://www.jeroenwijering.com/?item=JW_FLV_Media_Player use v.1.5

Dec. 04, 2008herman

i am trying to use jwplayer with highslide.... but when i close the highslide popup, the jwplayer keeps playing the movie.
How can i get it stopped the same time when i close the highslide window?

Regards,

Herman.

PS. I think its a beginners question, but i search all night but coulndt find anything.

Dec. 05, 2008andersen

@herman - you will have to issue a sendEvent("STOP") from the close button, just before it closes the window...

please see the - http://www.jeroenwijering.com/?item=Javascript_API_Examples
for code examples like - http://home5.inet.tele.dk/nyboe/flash/mediaplayer4/JW_API_xmpl_5-1-0-0.html

please note that the above examples all use the swfobject v.2.1 - http://code.google.com/p/swfobject/

Nov. 19, 2009mrljk3

andersen --

how about some ENGLISH examples.. geeze

Nov. 19, 2009mrljk3

This is the issue -- add this around line 427 in your fancybox code (which jwplayer uses)

$("#fancy_content").empty();


fixes the problem

Add a reaction

You can also return to the category or try this search for related threads.


 

Search the Forums

Go

Support

Support Here are some helpful links to learn more about the JW Player™:

Monetize Your Video

Monetize Your Video Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!

Why Buy a License?

Why Buy a License? If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.