
How to get state of player
Hello,
I want state of player.Is ...Hello,
I want state of player.Is file IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
etc.I am using flash player and javascript.Please resolve my problem.
Thanx.
Hello,
I want state of player.Is ...Hello,
I want state of player.Is file IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
etc.I am using flash player and javascript.Please resolve my problem.
Thanx.
Hi hobbs,
I used the function given by you,but its not working as it is not getting playerReady obj. I included swfobject.js. what should I include more to get playerReady obj.
Thnx.
How do you know that the player isn't calling playerReady()?
In your Flash embedding code, you have to use a player id in three places, the name attribute, the id attribute, and the id flashvar.
Post your full page code or a link to your Test Page so someone can help you further.
hi hobbs,
Thanks for reply
Here is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JW API Example 4-3-2-0 - JW FLV Media Player</title>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var currentState = "NONE";
var previousState = "NONE";
var player = null;
function playerReady(thePlayer) {
alert("id"+player.id);
player = document.getElementById(thePlayer.id);
addListeners();
}
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;
alert(currentState);
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.longtailvideo.com/players/jw-flv-player/";
}
}
function createPlayer() {
var flashvars = {
file:"Ad_Samsung_AC_Z2.swf",
autostart:"true"
}
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
}
var attributes = {
id:"player1",
name:"player1"
}
swfobject.embedSWF("player.swf", "placeholder1", "320", "196", "9.0.115", false, flashvars, params, attributes);
}
</script>
</head>
<body onload="createPlayer();">
<a href="http://www.longtailvideo.com/players/jw-flv-player/">JW FLV Media Player</a><br>
Checking the ModelListener "State" and redirecting after playing.<br>
(Please click the "Back" button to return to this page.)<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>
I have used the player id and name just once.
Any other places where we have to add id?
hello ,
please help me to resolve my problem.
Hello hobbs
I made some changes in the code which you have given.From which I am getting only buffering and playing state.But not getting completed state.How i will get that state.
Sorry, it won't work with a SWF file. Convert *Ad_Samsung_AC_Z2.swf* to FLV or MP4.
See: *http://developer.longtailvideo.com/trac/wiki/FlashEvents#Modelevents*
You have two choices:
1) setup a Model Listener - the current STATE will be available as soon as it changes,
2) use player.getConfig()['state'] to get the current state when you need it.
YoucanaddtheModelListenerSTATElikethis:bc.. <scripttype="text/javascript">
varplayer=null;
varplaylist=null;
varcurrentState=null;
functionplayerReady(obj)
{
player=gid(obj.id);
addListeners();
};
functionaddListeners()
{
playlist=player.getPlaylist();
if((playlist!==null)&&(playlist.length>0))
{
player.addModelListener('STATE','stateMonitor');
}
else
{
setTimeout("addListeners();",100);
}
};
functionstateMonitor(obj)
{
currentState=obj.newstate;
//...dosomethingherebaseduponthestateoftheplayer
//...onlyfortesting
alert('State:'+obj.newstate);
};
functiongid(name)
{
returndocument.getElementById(name);
};
</script>