views:

32

answers:

2

i'm using jwplayer for my flv files i try to change by Javascript the source of the flv file in the object so i can switch between 2 video files (or more) is any way to do so?

A: 
var s1 = new SWFObject("YourSourceHere.swf","","","","","");

this gets set in the swf object as far as i know... unless i am totally off track here :)

Dusty Roberts
A: 

The way to do this is to wait for the player to startup, grab a reference to it, then use the JavaScript API to programmatically load a new file. You'll need to make sure that when you embed the player, the 'allowscriptaccess' parameter is set to always, vis-a-vis:

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

<div id='mediaspace'>This text will be replaced</div>

<script type='text/javascript'>
  var so = new SWFObject('player.swf','ply','470','320','9','#000000');
  so.addParam('allowfullscreen','true');
  **so.addParam('allowscriptaccess','always');**
  so.addParam('wmode','opaque');
  so.addVariable('file','video.mp4');
  so.write('mediaspace');
</script>

Once the player has successfully started up, it will call a JavaScript function named playerReady, assuming it exists. From there you can grab a reference like so:

var player;
function playerReadyCallback(obj) {
     player = document.getElementById(obj['id']);
}

Finally, when you want to actually load a new file, just send a load event, like so:

player.sendEvent('LOAD', 'video-2.mp4');

For more information, see the JavaScript API and the events reference documentation.

Best,

Zach

Developer, LongTail Video

zach at longtail