Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

cannot get playpause to work

47 replies [Last post]

Ok, I cannot figure out what to do to get this to work. So here it is:

Here is the functions I have related to this:

<script type="text/javascript" src="swfobject.js">
</script>
<script>
var started = false;
function sendEvent(typ,prm) {

thisMovie('mpl').sendEvent(typ,prm); };

function getUpdate(typ, pr1, pr2, pid) {
if(typ == 'state') {
if((pr1 == 2) && (started == false)) {
// remember that player is started
started = true; }
// keep checking to see if player is completed
if(pr1 == 3) {
// reset started because player is completed
started = false;
// make him disappear
document.getElementById('id').style.visibility = 'hidden'; }
}
};

function thisMovie(movieName) {
if(navigator.appName.indexOf('Microsoft') != -1) {
return window[movieName]; }
else {
return document[movieName]; }
};

Here is the embed and the button:

<embed src="http://www.mysite.com/TrainVid/mediaplayer.swf" width="400" bgcolor="0xccc3ad" height="300" allowfullscreen="true"allowscriptaccess="always"flashvars="&file=http://www.mysite.com/TrainVid/test.flv&height=300&displayheight=300&showicons=false&width=400&autostart=true&javascriptid=mpl&enablejs=true&type=flv" />

<BR><BR><center><input type=button value="button" onClick="javascript:sendEvent('playpause',0); return false;">

When I try it, I get this error (which seems to be pointing to this line: thisMovie('mpl').sendEvent(typ,prm); };)

'undefined' is null or not an object.

Anybody?

Thanks,
Doc

Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

  <title>tthdoc</title>

  <script type="text/javascript">
    var started = false;

    function sendEvent(typ, prm)
    {
      thisMovie('mpl').sendEvent(typ, prm);
    };

    function getUpdate(typ, pr1, pr2, pid)
    { 
      if(typ == 'state')
      {
        if((pr1 == 2) && (started == false))
        { 
          // remember that player is started 
          started = true;
        } 
        // keep checking to see if player is completed 
        if(pr1 == 3)
        { 
          // reset started because player is completed 
          started = false; 
          // make him disappear 
          document.getElementById('mpl').style.visibility = 'hidden';
        } 
      } 
    };

    function thisMovie(movieName)
    {
      if(navigator.appName.indexOf('Microsoft') != -1)
      {
        return window[movieName];
      }
      else
      {
        return document[movieName];
      }
    };
  </script>

</head>

<body>

  <object id="mpl" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="300">
    <param name="movie"             value="http://www.mysite.com/TrainVid/mediaplayer.swf" />
    <param name="quality"           value="high" />
    <param name="allowfullscreen"   value="true" />
    <param name="allowscriptaccess" value="always" />
    <param name="flashvars"         value="width=400&height=300&displayheight=300&file=http://www.mysite.com/TrainVid/test.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
    <embed src="http://www.mysite.com/TrainVid/mediaplayer.swf" name="mpl" width="400" height="300" bgcolor="0xccc3ad" allowfullscreen="true" allowscriptaccess="always" flashvars="width=400&height=300&displayheight=300&file=http://www.mysite.com/TrainVid/test.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
  </object>
  <br />
  <br />
  <center>
    <button onClick="javascript:sendEvent('playpause'); return false;">Play/Pause</button>
    <button onClick="javascript:document.getElementById('mpl').style.visibility = 'hidden'; return false;">Hidden</button>
    <button onClick="javascript:document.getElementById('mpl').style.visibility = 'visible'; return false;">Visible</button>
  </center>

</body>

</html>

I still don't see what is wrong with what I have done. It seems redundant to have the object code with the parameters there and still have the embed code there? The only change in the embed code I see is name="mpl" but it already had javascriptid=mpl, are they different? You also added visibility buttons which I do not need. I am also trying to understand that the sendEvent function asks for 2 parameters, yet sending playpause is only 1? Could you please explain the rationale for what you are suggesting.

Thanks
Doc

For an explanation of the object/embed codes, please see this authority: [url=http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_4150]Macromedia Flash OBJECT and EMBED tag syntax[/url]. They know a lot more than I do.

No one uses the object/embed method (except on social networking sites) because it is very limiting. I NEVER use it, so I cobbled together something that worked, but is hardly the best.

The buttons were only for testing, is your delete key broken or what?

These are all of the available sendEvent() calls, some have a parameter, some don't.

  function sendEvent(typ, prm)
  ============================
  typ: complete
  typ: audio
  typ: captions
  typ: fullscreen
  typ: getlink    prm: index
  typ: next
  typ: playitem   prm: index
  typ: playpause
  typ: prev
  typ: scrub      prm: seconds (000.00)
  typ: stop
  typ: volume     prm: percent

The javascriptid of 'mpl' and the player name of 'mpl' are two different parameters that must be the same for any given player.

I didn't write the JW FLV Media Player code or the Adobe Flash Player code, or the various browser codes, or the operating sysstem codes, so I can't give you detailed explanations of why you have to do things, I just know what works most of the time, and what doesn't work most of the time.

It seems to me that when someone freely volunteers a lot of their time to try to help you, that you could be a little more respectful and a lot less whiney.

Forgive me if I came across as being not respectful and whiney. It was not my intention at all. I am very grateful for any help I receive, and appreciate the feedback you have given. I checked out the link you suggested and I do have a better understanding of the embed and object coding. Once again, I am sorry for any misunderstanding of my appreciation of your time and suggestions.

Thanks again
Doc

Ok, here is an update. I replace the embed code with the object/embed code combo as you listed above. I decided to try running the site in firefox and it works fine. But now when I run it in IE, I get a different error. I could not figure out where it was coming from, so I ran Microsoft debugger. The error said line 49 Char 5 unspecified error. With the debugger running, when I click the toggle play/pause link, the debugger pops up with a runtimre error. The debugger pointed to this line (which is not in my page, but not sure where it is located. Anyway, here is the function line it is pointing to. (I am pasting the whole function, but bold is the line in question.

function __flash__addCallback(instance, name) {
instance[name] = function () {
return eval(instance.CallFunction("<invoke name=\""+name+"\" returntype=\"javascript\">" + __flash__argumentsToXML(arguments,0) + "</invoke>"));
}
}

And here is the section from my source code..(just in case something got messed up with the cut and paste)

<object id="mpl" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="300">
<param name="movie" value="http://www.mysite.com/TrainVid/mediaplayer.swf">
<param name="quality" value="high">
<param name="allowfullscreen" value="true">
<param name="allowscriptaccess" value="always">
<param name="flashvars" value="width=400&height=300&displayheight=300&file=http://www.mysite.com/TrainVid/test.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true">
<embed src="http://www.mysite.com/TrainVid/mediaplayer.swf" name="mpl" width="400" height="300" bgcolor="0xccc3ad" allowfullscreen="true" allowscriptaccess="always" flashvars="width=400&height=300&displayheight=300&file=http://www.mysite.com/TrainVid/test.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true">
</object>

Any ideas?

Thanks,
Doc

Well, I may have screwed up on the names because I'm not that familiar with the object/embed naming convention. Let me dig into this a bit.

      ...Later

Try this:

Remove this: id="mpl"
Add this:<param name="id" value="mpl" />

And all of the param tags and the embed tag are supposed to end like this " />" ( space - forward slash - greater than sign )

Thanks so much for your help. I fixed the id tag and changed the param to end with "/>" and this got rid of the error. But now I have a new error which was the same error I was originally faced with:(. The debug now comes up with Line 19, 'undefined' is null or not an object. And it is pointing to this line (in bold):

function sendEvent(typ,prm) {
thisMovie("mpl").sendEvent(typ,prm)
}

I have tried every combination and alerts to check values and cannot figure this out. I have looked at various example players that work fine, and they all seem to be coded the same, so I am at a loss. I will list the relevant code areas again here, just in case I am overlooking something obvious. Thanks again in advance for your help.

function thisMovie(movieName){
if(navigator.appName.indexOf("Microsoft") != -1){
return window[movieName];
}else{
return document[movieName];
}
};

and

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="300">
<param name="id" value="mpl" />
<param name="movie" value="http://www.veteranspro.com/TrainVid/mediaplayer.swf" />
<param name="quality" value="high" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="flashvars" value="width=400&height=300&displayheight=300&file=http://www.veteranspro.com/TrainVid/test.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
<embed src="http://www.veteranspro.com/TrainVid/mediaplayer.swf" name="mpl" width="400" height="300" bgcolor="0xccc3ad" allowfullscreen="true" allowscriptaccess="always" flashvars="width=400&height=300&displayheight=300&file=http://www.veteranspro.com/TrainVid/test.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
</object>
<center><a href="javascript:sendEvent('playpause')">Toggle it</a></center>

Thanks
Doc

This has taken a real toll on my sanity; it seems that you need to declare both name and id.

  <object id="mpl" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="300">
    <param name="movie"             value="http://www.veteranspro.com/TrainVid/mediaplayer.swf" />
    <param name="id"                value="mpl" />
    <param name="quality"           value="high" />
    <param name="allowfullscreen"   value="true" />
    <param name="allowscriptaccess" value="always" />
    <param name="flashvars"         value="width=400&height=300&displayheight=300&file=http://www.veteranspro.com/TrainVid/test.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
    <embed id="mpl" name="mpl" src="http://www.veteranspro.com/TrainVid/mediaplayer.swf" width="400" height="300" bgcolor="0xccc3ad" allowfullscreen="true" allowscriptaccess="always" flashvars="width=400&height=300&displayheight=300&filehttp://www.veteranspro.com/TrainVid/test.flvlv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
  </object>

Thank you, thank you, thank you!! That did the trick! The toll on your sanity was not in vain! You have restored my sanity as well:)

Thanks again....
Doc

Now perhaps you can understand why the SWFObject method is preferred.

Anyway, enjoy and come back for more help if you need it.

ARGH! Thought I had this licked. All works fine but I forgot to double check on Firefox. The playpause toggle did nothing in Firefox. First I added an alert box under the SendEvent function to see if the toggle was even working. It was. So I added an alert with the typ and prm and saw it coming up as playpause, undefined. So I figured maybe firefox didn't like undefined so I changed it to 0. Firefox show now playpause, 0 but still does not work (and IE still does). Am I on the right track just using the wrong prm value, or could it be something else? And just FYI, when I click the Toggle It link in firefox, the link itself jumps up a litte where in IE it does not move.

Also, just a quick sidenote. I have the player on a layer that is hidden until a form is filled out. When you submit the form, the player appears. In IE, even set to autostart it does not begin playing until it becomes visible, but in Firefox starts right away. I can set flashvar to autostart=false, but which sendEvent should I use to start it when I make it visible? Would it be playpause or something else?

Thanks
Doc

I don't use FireFox (too buggy, too small market share), but according to these guys [url=http://www.ozzu.com/flash-forum/javascript-flash-firefox-t74795.html]Javascript to Flash & Firefox[/url] (see post of March 2nd, 2007) Firefox returns a nodelist instead of an object. They show code to deal with that. I suggest that you try it.

Check the Flash Player version. If it is 9,0,45 or 9,0,47, etc, update it to 9,0,115 or uninstall verion 9 and install version 8.
I had the same problem with the debugger saying "object undefined" in __falsh_xxxx function. It seems that there is a problem with javascript event registration with those version.

I hope that helps ;)

Ok, I feel like I am in the twilight zone. Please, please wake me up and tell me it is a dream! For some reason the errors are back. I created a page and took it down to the least common needed stuff (just 2 functions and the player code). I used the shortest video. I cleared the IE cache. I deleted and reuploaded mediaplayer.svf and swfobject.js. It is throwing the same error again. I tried to step by step recreate it and it still is doing it. I am ready to scream:(. I would appreciate it more then words could express if you could just go to this site and see what happens. I am getting the unspecified error again. Could you view source and see if you see anything I missed? The site is www.veteranspro.com/TrainVid/test.php.

Thank you
Doc

Plays Ok for me in IE6 & Opera.

When you're changing files and testing, append a random number to the URI to make sure that you get a fresh file from your server and aren't seeing an old version from the browser's cache, especially on IE.

www.veteranspro.com/TrainVid/test.php?12
www.veteranspro.com/TrainVid/test.php?123
www.veteranspro.com/TrainVid/test.php?1234

Ok, I need to follow my own rules sometimes:). I tried the random number and it still didn't work. So I decided to listen to what I always tell other people who say something on their computer isn't working but it worked yesterday. "Did you reboot?". A DUH moment. So I reboot, and all is working fine. Thanks for the response...

Doc

Greetings, I'm having a similar issue with the "unknown exception" in IE.

Its thrown here:

function __flash__addCallback(instance, name) {
  instance[name] = function () {
return eval(instance.CallFunction("<invoke name=\""+name+"\" returntype=\"javascript\">" + __flash__argumentsToXML(arguments,0) + "</invoke>"));
  }
}

with name = "addItem", arguments are:
[0] file = "rtmp://mystreamserverurl/vod/_definst_", id="my_flv_movie_without_extension", title="some title", type="rtmp"
[1] 0
length = 2

Here's my most verbose embed ...

<!--[if IE]><object id="flashplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="640" height="480">
<param name="movie" value="mediaplayer.swf" />
<param name="allowfullscreen" value="true" />
<param name="id" value="flashplayer" />
<param name="allowscriptaccess" value="always" />
<param name="flashvars" value="width=640&height=480&enablejs=true&repeat=list&autostart=false&shuffle=false&javascriptid=flashplayer&displayheight=300" /><embed src="mediaplayer.swf" name="flashplayer" id="flashplayer" width="640" height="480" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" flashvars="width=640&height=480&enablejs=true&repeat=list&autostart=false&shuffle=false&javascriptid=flashplayer&displayheight=300" />
</object>
<![endif]-->

I've tried every combination of specifying the name and id; as params, attributes to object and embed tag, flashvars etc.
I've tried with/without the type="application/x-etc".
I've tried using the full URL for mediaplayer.swf

Rebooting doesnt fix anything either ;)

The one thing is that I don't know the file URL until page load so I add them dynamically using addItem. Initially theres just an "undefined" item in the playlist, but using the SWObject method (works in FF 100%, IE like 5% only my machine so far) I can just removeItem and leave the items I queued up.

Does anything look out of whack in those tags? I'm SO close to have it work ... just this one bug...

Is your function __flash__argumentsToXML(arguments,0) returning a JavaScript object?

You don't show the function and the output you show is not in object notation, so it's unclear just what you are sending to addItem().

__flash__argumentsToXML(arguments,0) returns:

<arguments><object><property id="file"><string>rtmp://mystreamserverurl/vod/_definst_</string></property><property id="id"><string>my_flv_movie_without_extension</string></property><property id="type"><string>rtmp</string></property><property id="title"><string>Part 1 - 03/03/2008 1:00:04 PM</string></property></object><number>0</number></arguments>

which is a "String" type. instance is a "DispHTMLObjectElement" type, arguments is an "object.

One step up the call stack:

this._player.addItem({file:this._streamServerURL,id:vid,type:'rtmp',title:vidtitle},idx);

where this._player is a DispHTMLObjectElement (via thisMovie, or getElementById or $get, all result in same behavior)
this._streamServerURL is a string "rtmp://mystreamserverurl/vod/_definst_"
vid is a string, "my_flv_movie_without_extension",
vidtitle is a string, "Part 1 - 03/03/2008 1:00:04 PM",
idx is of type Long, value is 0.

I think I got it. Crossdomain scripting... it seems I have to specify the full URL to the medaiplayer.swf ... otherwise it thinks its in another domain for some reason even though its in the same directory as the page that refers to it.

... next, the click to activate issue.

One other thing.... it only works with 9,0,115,0 ... and definitly NOT with 9,0,28,0 ....

@cfairies,

The ExternalInterface had quite a few bugs in earlier versions of Flash 9. They seem to be fixed in v9,0,115,0.

Click ot activate goes away if you use SWFObject...

I`ve got same error when I tried to make a player dynamicly loads the files. What I have found as an error is:
---------------------------------------------------------------------------
function thisMovie(swf) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[swf];
} else {
return document[swf];
}
};
---------------------------------------------------------------------------
That was the regular code from package I have downloaded. I assume MS IE 7.0 has changed the understandning of window[...] and I made it document[..] and that solves the problem and made my life easier. Now it looks like:

---------------------------------------------------------------------------
function thisMovie(swf) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return document[swf];
} else {
return document[swf];
}
};
---------------------------------------------------------------------------
....and works!

Would that code be equivalent to

function thisMovie(swf){
return document[swf];
};

???

@Dieselpop - yes, and my guess is it wont work in IE6 at all (havent access to one)
so i wonder what happened for musician and what the actual real error was, as the original code works fine in all browsers i try

I am also getting the same error i.e sendEvent not a function , could some help me !

@Arun - sendEvent not a function

have you included the the function sendEvent in your code?

such messages are often seen when using the javascript offline (it only works online!)
or when the name/id of the player is wrong, make sure you use the same name/id everywhere -
the name/id is easiest to get right by using the swfobject method of embedding -

a link to your testpage would make it less quesswork what might be the problem...

Can we get the flashvars values dynamically and change dynamically from below code using javascript, plz let me know and thanx.

<object id="mpl" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="300" height="250">
<param name="movie" value="mediaplayer.swf" />
<param name="quality" value="high" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="flashvars" value="width=300&height=250&displayheight=230&file=afraid.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
<embed src="mediaplayer.swf" name="mpl" width="300" height="250" bgcolor="0xccc3ad" allowfullscreen="true" allowscriptaccess="always" flashvars="width=300&height=250&displayheight=230&file=afraid.flv&showicons=false&autostart=true&javascriptid=mpl&enablejs=true" />
</object>

@sonu - no that is not really possible im afraid - but if you use the swfobject method for the embedding such will be possible

i know little bit with swfobject ,but how to get the flashvars values dynamiclly and i want to change that values dynamically , how to do that
plz tel me that.
Thnx

please see this thread, in particular posting of 04.04.2008: http://www.jeroenwijering.com/?thread=3523

Tnx andersen..
I saw that code it is very nice and worked for me, the flashvar are dynamically passed while creating the player,it is OK, but if i directly write the flashvar values directly like below insted of dynamically passing, after that can we dynamically get that flashvar values.plz let me know

var s1 = new SWFObject("mediaplayer.swf", 'flvid', '350', '250', '9');
s1.addParam('allowfullscreen', 'true');
s1.addParam("allowscriptaccess","always");
s1.addVariable('width', '350');
s1.addVariable('height', '250');
s1.addVariable('displayheight', '230');
s1.addVariable('file', 'demo.flv');

s1.addVariable('javascriptid','flvid');
s1.addVariable('autostart', 'true');
s1.addVariable('enablejs','true')
s1.write('divid');

Tnx again andersen.

Hello,

I had the problem with not being able to dynamically load a swf and add a callback. After much removal of hair I finally found a way to handle it for IE... (I am using IE6)

Here is my Javascript function I adapted to get the SWF movie by name...

function getSWF(movieName)
{
var swfMovie;

var isIE = navigator.appName.indexOf("Microsoft") != -1;
if (isIE) swfMovie = window[movieName]; else swfMovie = document[movieName];
//check if it is embedded in a form...
if ( swfMovie==undefined ) eval("swfMovie = document.forms[0]."+movieName);

// Assign global movie name var to the swfMovie to help flash find the object when adding callback
eval( movieName + " = swfMovie;" );

return swfMovie;
}

I also have a toggleVisibility function that is called via a Javascript event (onclick). At first I tried calling my getSWF from the toggleVisibility function, but I found that the callback method added by Flash (allowing me to call into flash from JS) couldn't be accessed immediately. So to remedy this I used setTimeout to continue trying until the callback method added by flash was not null. This worked great...

function setQueuedValue(swfObjectID)
{
//swfObjectID should contain the id of the swf as is defined in the object tag (see HTML snippet below)
var mySWFobject = getSWF(swfObjectID);
if ( mySWFobject.setValue != null )
{
var hiddenTextField = getControl("HIDDEN_" + swfObjectID);
var valueToSet = hiddenTextField.value;
mySWFobject.setValue(valueToSet);
}
else
{
setTimeout("setQueuedValue('"+swfObjectID+"')",10);
}
}

(The setValue method is defined in action script and a callback is added for it there too, but it takes a little bit of time for it to become valid hence the usefulness of setTimeout in this situation.)

HTML that I use to embed my SWF object...

(Note: You would call setQueuedValue( "MY_SWF_OBJECT" ); when the visibility of your swf object is toggled. This object HTML code is embedded inside a DIV whose visibility I can toggle. As soon as it is toggled to visible that's when I call setQueuedValue. I discovered you can't communicate with the flash SWF while it is inside a div with visibility set to false. But you can queue a value to be set while it is invisible and then repeatedly try to set the queued value as soon as it does become visible until the callback is successfully added.)

<object id="MY_SWF_OBJECT" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="186" height="166" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="mySwf.swf" />
<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />
</object>

Note that this solution is for IE. You may be able to tweak it to work in other browsers too if neccessary using the same idea. Hope this helps someone...

-Will

@willjones
Nice discovery will! I encountered the same problem too. Flash-js communication was working in one page but not the other, with essentially the same js code.

Then I figured that it could be a HTML tag related problem, so I took the object/embed code out of a Form tag, and WOALA!
It Worked. Then I googled with the problem and found your discovery. I wish I would find it earlier. Any ways, hope other people will, before destroying their sleep at night.

Oh, and later I found out in this link: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html, that :- "Flash Player does not currently support SWF files embedded within HTML forms."

@willjones and fayazmiraz

to use the javascript for a player inside a form or asp/.net pages you can use the swfformfix (or maybe swfobject2)

please see these threads - http://www.jeroenwijering.com/?search=swfformfix

javascript interaction will not work in all browsers if the player is invisible/hidden -
best is to hide by making the container size=0

rather than using timeouts with fixed times, you can check that the player is ready by making sure the "state" == 0

please see the "Javascript interaction" page for more info - http://www.jeroenwijering.com/?item=Javascript_interaction

as well as the source of these demos on the demopage:

http://home5.inet.tele.dk/nyboe/flash/mediaplayer/javascript.htm
http://home5.inet.tele.dk/nyboe/flash/mediaplayer/autostartspecific.htm
http://home5.inet.tele.dk/nyboe/flash/mediaplayer/loadandplay.htm
http://home5.inet.tele.dk/nyboe/flash/mediaplayer/mousedropping.htm
http://home5.inet.tele.dk/nyboe/flash/mediaplayer

@ anderson

javascript interaction will not work in all browsers if the player is invisible/hidden -
best is to hide by making the container size=0

I am trying to start playing multiple media players (using 4.0beta) by javascript API and made the following discovery:
In all browsers except IE, players are are not initializing the API functionality until the player is fully visible. As you said, that means they must not have the style attributes visibility=hidden nor display=null.

You can take care of these style issues as author of the page but the much bigger problem is:
The media player has to be in view range of the page for initializing the API functions, meaning any javascript interaction won't work until the user scrolls down to the player!

Is this a bug? Is there a workaround to make it possible to initialize the players without being visible or in view range?

meaning any javascript interaction won't work until the user scrolls down to the player!

ouch - that sounds bad - i havent noticed that yet, but better post it as a possible bug in the bug reports forum to make sure !
http://www.jeroenwijering.com/?forum=Bug_Reports

It's the same with the v3.x (and possibly all Flash, I haven't tested it exhaustively) in all browsers except IE.

If you load a tabbed browser with Flash on a non-visible tab, the player doesn't instantiate until the tab is selected.

yes, i know about the tabbed issue - i read somewhere that is intentionally so for all flash in firefox to save ressources, which does make some sense - it easier for IE as it can just reuse all of windows - but the scrolling thing, i have not been able to reproduce it in IE, FF2 and FF3, i have tried by having a very small browser window and go to a player page and start the player by javascript - maybe its only on other platforms or maybe the actual problem is inlines creation of the player, so it just havent finished creating before the script starts? in which case a function triggered onload would solve the issue...

I made a small example that demonstrates the problem. As soon as you scroll down this page and the player objects comes into view range you'll get the message that the player has been initialized. I've tested this in Windows XP on Opera 9.5, FF3, Seamonkey 1.1.9 and Safari 3.1. Please try it. I already posted a bug report thread: http://www.jeroenwijering.com/?thread=11249

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Test JS API Initialization</title>
    <script type="text/javascript">
    function getPlayer(gid) {
        if(navigator.appName.indexOf("Microsoft") != -1) return window[gid];
        else return document[gid];
      };
      function playerReady(obj) {
        var id = obj['id'];
        var version = obj['version'];
        var client = obj['client'];
        alert("Player "+id+" is now ready for being controlled by JS API");
      };
    </script>
  </head>
  <body>
    <div style="min-width: 100%; min-height: 4000px; position: relative;">
      <h1>Test JS API Initialization</h1>
      <p>Please scroll down to the bottom of this page. The Player will be initialized then.</p>
    </div>
    <div>
      <object id="flashVideo" name="flashVideo" type="application/x-shockwave-flash" data="http://www.jeroenwijering.com/upload/player.swf" style="width: 320px; height: 196px;">
      <param name="movie" value="player.swf" />
      <param name="allowscriptaccess" value="always" />
      <param name="wmode" value="opaque" />
      <param name="type" value="video" />
      <param name="FlashVars" value="file=http://jeroenwijering.com/upload/bunny.flv" />
      <p><a href='http://www.macromedia.com/go/getflashplayer'>get the flash player</a> to see this player.</p>
      </object>
    </div>
  </body>
</html>

@ autostart

Your list of SendEvent() calls in #msg55119 above includes these:

  typ: audio
  typ: captions
  typ: fullscreen

Should I be able to control each of these features with a call to SendEvent()? For example, if I want to toggle captions with an HTML link, should I be able to do so like this?

<a href="javascript:sendEvent('myPlayer','captions');">Toggle captions</a>

You've peaked my curiosity because (a) I'd like to be able to do this, (b) it doesn't seem to work, and (c) these aren't among the events listed on http://www.jeroenwijering.com/?item=Javascript_interaction.

Thanks for any clarification.

These three sendEvent() calls toggle the buttons in the control bar on/off. The button remains visible, but it will be gray, indicating that the function is not available. ( I think audio also actually controls the audio, but it's been a while since I used it, so my memory is a bit fuzzy — you will have to try it for yourself. )

So if you had tracks with captions, the user could click on the button to turn the captions on and off. But if one track didn't have captions, you could disable the button for that track.

The actual use of the auxiliary audio, captions, and fullscreen is controlled by the use flashvars: useaudio, usefullscreen, usecaptions.

Of course, you can mix & match, so there are other combos, too numerous to mention, that are available — if you get creative.

Official list of all flashvars: http://www.jeroenwijering.com/?thread=10220#msg62741

Unofficial JavaScript API helper: http://willswonders.myip.org:8085/php/JavaScript API.txt

I tried AJAX's code in his first post. I cannot get the play/pause to work from that.I have tried in both FF and IE.

I battled this issue for days now. The problem: function names!!!!!

Check this site out:
http://blog.warptube.com/2008/12/2/oddities-with-externalinterface-and-ie

A really ugly issue with ExternalInterface can come up with naming your functions. You’re code will throw an error in code that looks something like:

function __flash__addCallback(instance, name) {
instance[name] = function () {
return eval(instance.CallFunction(”" +
__flash__argumentsToXML(arguments,0) + “”));
}
}

If you use: play, stop, tags, item, length, and likely some others I’m unaware of you will get an error inside Adobe’s JavaScript hook code. What’s happening is you inadvertently are screwing with some read only attributes of some IE functionality which is causing things to grind to a halt. My solution is to just prepend all my addCallback routines with an underscore.

Hi

when i pause the video it displays the last frame, along with the video controls. Then after leaving the browser untouched, anywhere from 5 mins or sometimes longer, the player window suddenly goes completely black with the video controls.When play button is clicked,it starts to play from the beginning.I am unable to get that video played, from where i paused.

Hi Reena,

Can you please post a link to a page demonstrating this?

Post new comment

  • Allowed HTML tags: <code> <blockquote> <em> <strong> <strike> <ul> <li> <ol>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic).

More information about formatting options