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

Forums

/

Trouble with player.sendEvent('LOAD'

5 replies [Last post]

Hi,

I am trouble getting the player to load from a link and a playlist using the player.sendEvent('LOAD') command: I have been successfully used the sendEvent command to run properly so I am hoping for a really easy solution:

I can load a the same link using flashvars but not sendevent(LOAD).

here is my code:

<head>
<title>JW WRK 5</title>

<script type="text/javascript" src="http://www.zebamay.com/dev001/mediaplayer4_4/swfobject.js"></script>
<script type="text/javascript">

var currentState = "NONE";
var previousState = "NONE";
var player = null;

function playerReady(thePlayer) {
player = document.getElementById(thePlayer.id);
addListeners();
addViewListener();
}

function addListeners() {
if (player) {
player.addModelListener("STATE", "stateListener");
} else {
setTimeout("addListeners()",100);
}
}

function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
currentState = obj.newstate;
previousState = obj.oldstate;

var tmp = document.getElementById("stat");
if (tmp) {
tmp.innerHTML = "current state: " + currentState +
"<br>previous state: " + previousState;
}

if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) {
document.location.href="http://www.jeroenwijering.com/?item=JW_FLV_Media_Player";
}
}

function addAllViewListeners() {

player.addViewListener("STOP", "doNothing"); //{id,client,version}.
player.addViewListener("VOLUME", "doNothing"); //{position,id,client,version}.e.

}

function createPlayer(thePlayer, theFile) {
var flashvars = {
file:'&file=http://scfire-ntc-aa02.stream.aol.com:80/stream/1010/;stream.nsv&type=sound',
autostart:"true"

}
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"

}
var attributes = {
id:"player1",
name:"player1"
}
swfobject.embedSWF("http://www.zebamay.com/dev001/mediaplayer4_4/player.swf", "placeholder1", "320", "196", "9.0.115", false, flashvars, params, attributes);

}
</script>

</head>
<body onload="createPlayer()"

<a href="http://www.jeroenwijering.com/?item=JW_FLV_Media_Player">JW FLV Media Player</a><br>
<br>
<a href="JavaScript:player.sendEvent('PLAY')">play/pause toggle</a><br />
<a href="JavaScript:player.sendEvent('MUTE')">mute/sound toggle</a><br />
<br>
<a href="#" onclick="JavaScript:player.sendEvent('STOP')">stop playing and buffering</a>
<br>
<a href="#" onclick="player.sendEvent('VOLUME', 50)">set absolute volume 50%</a>
<br>
<a href="#" onclick="player.sendEvent('VOLUME', 100)">set absolute volume 100%</a>
<br />
<a href="#" onclick="player.sendEvent('STOP')">Stop</a><p>

<a href="#" onclick="player.sendEvent('STOP');

player.sendEvent('LOAD', '&file=http://scfire-ntc-aa02.stream.aol.com:80/stream/1011/;stream.nsv&type=sound');
">Load from a link </a>
<br>
<a href="#" onclick="player.sendEvent('STOP');
player.sendEvent('LOAD',
'http://content.bitsontherun.com/videos/qyehIiBT.flv');
">load and Play a Video </a>
<br>

<a href="#" onclick="player.sendEvent('STOP');
player.sendEvent('LOAD',
'http://www.zebamay.com/dev001/playlist1/playlist.xml');
">Load and play a Playlist </a>
<br>
<a href="#" onclick="player.sendEvent('STOP');
player.sendEvent('LOAD',
'http://www.zebamay.com/dev001/playlist1/playlist.xml, 1');
">Play track2 of Playlist </a>
<br />
<br />
<div id="placeholder1">
<a href="http://www.adobe.com/go/getflashplayer">Get flash</a> to see this player
</div>
<br>

<div id="stat"></div>

</body>
</html>

Any help on getting these 3 issue resolved would really help getting further along.

Thanks,

See: http://developer.longtailvideo.com/trac/wiki/FlashEvents#Viewevents

You have an extra parameter "1" after the playlist URI.

player.sendEvent('LOAD',
'http://www.zebamay.com/dev001/playlist1/playlist.xml, 1');

Better:

player.sendEvent('LOAD',
'http://www.zebamay.com/dev001/playlist1/playlist.xml');

Wrong format in this code.

player.sendEvent('LOAD', '&file=http://scfire-ntc-aa02.stream.aol.com:80/stream/1011/;stream.nsv&type=sound');

Better:player.sendEvent('LOAD', {'file':'http://scfire-ntc-aa02.stream.aol.com:80/stream/1011/;stream.nsv', 'type':'sound'});

Thank you, I managed to get most of my issues sorted with your assistance.

My next question is if there is a better way to play the 2nd track in the playlist?

here is the code i am currently using:

player.sendEvent('LOAD',
'http://MYDOMAIN.com/playlist1/playlist.xml');
player.sendEvent('ITEM',2);
player.sendEvent('PLAY')

Cheers

With one correction:player.sendEvent('PLAY'<strong>, 'true'</strong>);Without the boolean, it toggles the play state, which may not be what you want.

That's the correct way to:

1) load a new playlist (if you need to load a new playlist rather than using the already loaded playlist),

2) select the track,

3) start the player.

{Some releases start the player when you select an item, but it doesn't hurt to send the PLAY Event anyway.)

Hi, i'm also having trouble trying to load a playlist from a JS function. I was formerly loading a single video on the player (no playlist), with the possibility of changing it anytime by clicking on a link. Now that I have a playlist with some "default" videos loaded, the function that did the dynamic load of the videos on the links stopped working.
Note that I'm using two different playlists, one for the autoplay, and other holding all the videos linked in the page.

Here's the code for the JS:

var so = new SWFObject(server+'/player.swf','mpl','620','415','9');
so.addVariable('file',server+'/play/play.xml');
so.addVariable('autostart','true');
so.addVariable('repeat','always');
so.write('mediaspace');

function changeVideo(videoNum){
            var player = document.getElementById("mpl");
            player.sendEvent('LOAD', server+'/highlight/highlight.xml');
            player.sendEvent('ITEM',videoNum);
            player.sendEvent('PLAY', 'true');
}

A link example:

<a href="javascript:changeVideo(3);">Watch</a>

Thanks in advance for any help you could provide.

Cheers

 
Depending on how fast your playlist loads, the player needs some time to retrieve and index the playlist.

Therefore, you can't index and play immediately after loading a playlist.

The best way to do this is to use the PLAYLIST Listener, which is fired after the playlist is loaded.

You can see this being done in this Test Page:

    http://willswonders.myip.org:8074/player5/Chet_Test_Simplified.html

Look for the playlistMonitor(obj) (line 84) and the loadPlaylist(url, item) (line 118) functions, as well as your changeVideo(videoNum) (line 127) function.