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

playerReady function can't find player id

21 replies [Last post]

Hello,

I'm trying to make plyaerReady function work. But it can't get the player ID, the following function returns an alert "player null has been instantiated"

function playerReady(obj) {
var id = obj['id'];
var version = obj['version'];
var client = obj['client'];
alert('player '+id+' has been instantiated');
};

and the player is embedded as:

<script type="text/javascript" src="swfobject.js"></script>

<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>

<script type="text/javascript">
var so = new SWFObject('player.swf','playerID','500','400','8');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('width','400');
so.addVariable('height','220');
so.addVariable('file','rtmp://85.235.84.242:1960/simplevideostreaming/giresun.flv');
so.addVariable('javascriptid','playerID');
so.addVariable('enablejs','true');

so.write('container');
</script>

Hi Mustafa,

If you find a solution to the problem please post it here , I've got the very same problem.

The flashvars width, height, javascriptid, and enablejs are not supported by the v4.x player. Ref: http://code.jeroenwijering.com/trac/

If you are using the latest v4.1.55 player:

so.addVariable('file','giresun.flv');
so.addVariable('streamer','rtmp://85.235.84.242:1960/simplevideostreaming');

The player still did not get an id, currently using media player 4.0.46.

The mediaplayer 4.1.55 is not available in the svn repo.

Thanks for the response kLink.

Says r56, but the player identifies itself as v4.1.55http://code.longtailvideo.com/trac/browser/trunk/as3/player.swf
Works for me:

  streamer:             'rtmp://85.235.84.242:1960/simplevideostreaming',
  file:                 'giresun.flv',
plays a video with two straw cowboy hats in the foreground...

See this thread if you are trying to use the player over https / ssl instead of http:

http://www.jeroenwijering.com/?thread=11948

I've the same problem on linux. With the same code on windows, I can get the player id.

See also :
http://www.jeroenwijering.com/?thread=12417

id is also null on IE7, but it works with FF 3.0
I hope this will be fixed soon?

I am still unable to get an id under IE6/7 :(

Try each of these methods:

function playerReady(obj)
{
  player = document.getElementsByName(obj.id)[0];
  player = window.document[obj.id];
  player = document[obj.id];
  player = document.getElementById(obj.id);
  player = document.getElementById('playerId');
};
One at a time, of course. :)

No, the problem is, that obj.id/obj['id'] is 'undefined' or null in IE, not the JavaScript variable after retrieving the element. This is all I use:

<script type='text/javascript' src='swfobject.js'></script>
<script type="text/javascript">
function playerReady(obj)
{
var id = obj['id'];
var version = obj['version'];
var client = obj['client'];
alert(id+", "+version+", "+client);
};
</script>
<script type="text/javascript">
var pl1 = new SWFObject('player.swf','p1','250','187','8');
pl1.addParam('allowscriptaccess','always');
pl1.addVariable('file','audio.mp3');
pl1.write('player1');
</script>

Ok, I made a new test page, using this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">

function playerReady(obj)
{
var id = obj['id'];
var version = obj['version'];
var client = obj['client'];
alert(id+", "+version+", "+client);
}

</script>
</head>

<body>

<div id="preview"></div>

<script type='text/javascript' src='swfobject.js'></script>
<script type='text/javascript'>
var s1 = new SWFObject('player.swf','player','400','300','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=video.flv');
s1.write('preview');
</script>

</body>
</html>
which runs on xampplite. When I purge the cache of IE, the correct player id is found in 'obj' of the playerReady function, however, when I reload the page again (and every time after that), the player id is 'undefined' again. Until I purge the cache again, then I get the player id.

First, you are loading swfobject.js twice; not harmful, just unnecessary.

Second, I would use swfobject v2.1 which doesn't seem to have these problems. Put all of your JavaScript in the head element and let swfobject take care of loading at the correct point in the page loading process.

Third, the fifth method I posted above:player = document.getElementById('playerId');completely avoids using the object passed to playerReady() by the player, and should always work.

Putting all the java script in the head doesn't work, the player isn't instantiated at all (neither with swfobject 2.1, nor with swfobject 1.5). Furthermore the player doesn't get instantiated with swfobject 2.1, even if I put the javascript to instantiate the player after the <div>. I guess you actually mean to put the swfobject code somehwere in a document.ready function (of jQuery for example)?

Creating the swfobject with version 1.5 after the <div id="player"> has been defined and usingplayer = document.getElementById('playerId');works fine on FF and IE.

//Edit: damn, the same problem still remains withplayer = document.getElementById('playerId');It works in IE only once (and only for one player) :(

//Edit²: ah, I just noticed, that the API of SWFObject 2 is entirely different, will try with 2.1 again, once I figured out what I have to change :)

Ok, got it to work with swfobject 2.1 now and IE is able to retrieve the object correctly with getElementById. Unfortunately I have another problem now: in IE, the sendEvent call doesn't have any effect. IE seems to be able to execute the sendEvent function just fine though (at least I don't get the ".sendEvent is not a function" error).

<!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" lang="en" xml:lang="en">
  <head>
    <title>SWFObject dynamic embed - step 3</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">
swfobject.embedSWF("player.swf", "player", "300", "20", "9.0.0", false, { file: "audio.mp3" });

$(document).ready(function()
{
p = document.getElementById('player');
alert(p);
$("#player").mouseover(function () { alert("mouseover"); p.sendEvent('PLAY',true); });
});
    </script>

  </head>
  <body>
    <div id="player">
      <p>Alternative content</p>
    </div>
  </body>
</html>
This is taken straight from the example source of swfobject 2.1. I added jQuery in order to retrieve the object with document.getElementbyId in the document.ready function. alert(p) outputs "[object]" in IE. Then when I mouseover the player, it alerts correctly "mouseover" in IE and p.sendEvent doesn't give an error. However, the player doesn't play (or mute or whatever event I send him).

//edit: bah! just found out it is still the same problem. the sendEvent will work for the first player, the first time it is executed after the cache is cleared. What is going on here :(

I had a similar problem which i was able to fix with:

player = document.getElementById('jw_player');

var player = document.getElementById('mpl');
player.sendEvent('PLAY','false');

this fixes the 'Object does not support this method' error in IE6

- not sure why declaring the var in local scope should do it ... but it does!

I got the same problem, it's impossible to get back a playerid to control it with sendEvent function.
I tried with jQuery and all sorts of SWFObject emdedding... but with no results.

<!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" lang="en" xml:lang="en">
<head>
<title>SWFObject dynamic embed - step 3</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
var flashvars2 = {
//id:"PlayerID",
file:"video/multimedia_video.xml",
autostart:"true",
fullscreen:"true",
playlist:"none",
backcolor:"#333333",
frontcolor:"#FFD444",
skin:"video/skins/beelden/beelden.xml"
};

var parameters2 = {
allowfullscreen:"true",
allowscriptaccess:"always"
// wmode:"opaque" non funziona
};

var attributes2 = {
id:"thePlayer", 
name:"thePlayer"
};

swfobject.embedSWF("video/player.swf", "videoplayer", "640", "390", "9.0.115", false, flashvars2, parameters2, attributes2);

$(document).ready(function()
{
pid = document.getElementById('thePlayer');
alert('Passed Id is: '+pid);

});
</script>

</head>
<body>
<div id="videoplayer">
<p>Alternative content</p>
</div>
</body>
</html>

in the alert I always obtain a null value.. so it's impossible to control the player with the EVENTS model... any suggestions?
Thanks in advance ;-)
Alessio

<!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" lang="en" xml:lang="en">

  <head>

    <title>SWFObject dynamic embed - step 3</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    
    <script src="http://www.google.com/jsapi"></script>

    <script>
      google.load('swfobject', '2.2');
      google.load('jquery', '1.3.2');
    </script>

    <script type="text/javascript">
      var flashvars2 =
      {
        'playlistfile':                  'video/multimedia_video.xml', // v5 player
      //'file':                          'video/multimedia_video.xml', // v4 player
        'playlist':                      'none',
        'backcolor':                     '333333',
        'frontcolor':                    'FFD444',
        'skin':                          'video/skins/beelden/beelden.xml',
        'id':                            'playerID',
        'autostart':                     'true'
      };

      var parameters2 =
      {
        'allowfullscreen':               'true',
        'allowscriptaccess':             'always',
        'wmode':                         'opaque'
      };

      var attributes2 =
      {
        'id':                            'playerID',
        'name':                          'playerID'
      };

      swfobject.embedSWF('video/player.swf', 'player', '640', '390', '9.0.124', false, flashvars2, parameters2, attributes2);

      var pid = null;
      function playerReady(obj)
      {
        pid = document.getElementById(obj.id);
alert('Passed Id is: ' + pid.id);
      };
    </script>

  </head>

  <body>

    <div id="playercontainer" class="playercontainer"><a id="player" class="player" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Get the Adobe Flash Player to see this video.</a></div>

  </body>

</html>

playerReady() with version 5 of JW Player is again broken and I no longer can rely on it to give me a player ID. I used a workaround and just hardcoded the ID of the player inside the playerReady() event.

like so:

function playerReady(obj) {

// Not working: obj['id']

player = document.getElementById('ply');
// 'ply' is the id of the player
}

If you only have one player on the page there is no need to handle it dynamically anyways.
Linux will always be an oddball here.

saivert, I have the same exact problem. playerRead() only gets an ID on the given object if we're using IE. If we use any other browser, the ID is null.

I filed a report with the jwplayer staff on Jan 6, and just received an email from Zachary that he is still not sure what the problem is. We have had to go back to 4.x since we cannot hardcode the ID in our case.

I've gone ahead and opened a ticket for this:

http://developer.longtailvideo.com/trac/ticket/728

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