I have been recently trying ...I have been recently trying to create a media gallery for my website. I wanted to have a media library where I have ability to have different playlist i.e. basically links when clicked will change the playlist accordingly. Adding to this I wanted to separate the playlist from the video player (http://home5.inet.tele.dk/nyboe/flash/mediaplayer4/custom_playlist_advanced.html I don’t need the drag option) so that I can style it and place it elsewhere. Anyway I started playing around with the file shown in the link below. Everything works fine; only thing is, for the playlist to change I need to click the links twice. Once a playlist is loaded the movies within it plays fine. But again to load another playlist I have to click twice. It would be great if someone can review the ode and let me know what am doing wrong.
<html>
<!-- page by andersen -->
<head>
<title>JW FLV Media Player with customized playlist</title>
<style type=text/css>
body { padding:0px; margin:0px;
font-size:12px;
font-family:verdana,helvetica,arial;
background-color: #ffffff;
}
#playerroot { position:absolute; width:400px; height:268px;
border:#333 1px solid; border-bottom:0px;
background-color:#f4f4f4;
z-index:9999;
}
#listroot { position:absolute; width:400px; height:268px;
border:#333 1px solid;
background-color:#f4f4f4;
z-index:2;
}
#playerhandle { width:396px; padding:2px; margin:2px; color:white; background-color:#426300; font-weight:bold; }
#listhandle { width:396px; padding:2px; margin:2px; color:white; background-color:#426300; font-weight:bold; }
.playinglo { font:12px verdana,arial,helvetica,sans-serif; color:#000000; background-color:#c6ef74; }
.playinghi { font:12px verdana,arial,helvetica,sans-serif; color:#000000; background-color:#7bad00; vertical-align:top; text-align:left; }
.playlistlo { font:12px verdana,arial,helvetica,sans-serif; color:#000000; background-color:#7bad00; vertical-align:top; text-align:left; }
.playlisthi { font:12px verdana,arial,helvetica,sans-serif; color:#000000; background-color:#c6ef74; }
.playlistbox { width:400px; height:244px; margin:0px; border:#7bad00 1px solid; overflow:auto; }
</style>
<!--<script type="text/javascript" src="dom-drag.js"></script>-->
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var currentItem = -1;
var previousItem = -1;
var currentLength = 0;
var currentState = 'NONE';
var previousState= 'NONE';
var linkFlag = false;
var player = null;
function playerReady(thePlayer) {
//alert(thePlayer);
player = document.getElementById(thePlayer.id);
addListeners()
printPlaylistData();
}
function addListeners() {
if (player) {
player.addControllerListener("ITEM", "itemListener");
player.addModelListener("STATE", "stateListener");
} else {
setTimeout("addListeners()",100);
}
}
function itemListener(obj) {
if (obj.index != currentItem) {
previousItem = currentItem;
currentItem = obj.index;
setItemStyle(currentItem);
//alert("sdffsdfsd");
}
}
function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
currentState = obj.newstate;
//previousState = obj.oldstate;
var tmp = document.getElementById("itm" + currentItem);
if ((currentState != previousState)||(currentItem != previousItem)) {
previousState = currentState;
setItemStyle(currentItem);
}
}
function mover(obj, idx) {
if (idx == currentItem) { obj.className = 'playinghi'; }
else { obj.className = 'playlisthi'; }
}
function mout(obj, idx) {
linkFlag = false;
if (idx == currentItem) { obj.className = 'playinglo'; }
else { obj.className = 'playlistlo'; }
}
function setItemStyle(idx) {
var count = getLength();
for(var i=0; i<count; i++) {
var tmp = document.getElementById("itm" + i);
if (tmp) {
if(i == idx) {
if(currentState == 'PLAYING') { tmp.className = 'playinglo'; } //'playinghi';
else { tmp.className = 'playlisthi'; } //'playinglo';
} else { tmp.className = 'playlistlo'; }
}
}
}
function getLength() { currentLength = player.getPlaylist().length; return(currentLength); };
function printPlaylistData() {
var plst = null;
//var currentPlaylist;
var tmp = document.getElementById("plstDat");
//tmp.innerHTML == "";
plst = player.getPlaylist();
//plst = player.getPlaylist();
if (plst) {
//currentPlaylist = plst;
//alert("fsdfasdfasdf");
var txt='<table cellPadding="2" width="380">';
for(var i in plst) {
txt+='<tr><td><table width="370" id="itm' + i + '" onclick="player.sendEvent(\'ITEM\',' + i + ');" ';
txt+='class="playlistlo" onmouseover="mover(this, ' + i + ')" onmouseout="mout(this, ' + i + ')">';
txt+='<tr><td><img src="' + plst[i].image + '" width="90" height="68" title="Click to Play"></td>';
txt+='<td width="276" valign=middle><p>';
txt+=plst[i].title + '<br>';
txt+='<b>' + plst[i].author + '</b><br>';
txt+='<b>Duration ' + plst[i].duration + ' Mnts</b><br>';
txt+='<a href="' + plst[i].link + '" target="_self" title="' + plst[i].link + '"> more info</a><br>';
//txt+=plst[i].description;
txt+='</p></td></tr></table></td></tr>';
}
txt+='</table>'; //alert(txt);
if (tmp) { tmp.innerHTML = txt; }
} else {
setTimeout("printPlaylistData()",100);
}
}
function loadCheckedPlaylistData(theFileLoad) {
/*if (currentPlaylist) {
var j = 0;
var lst = new Array();
for(var i in currentPlaylist) {
//if(document.getElementById('cb' + i).checked) {
lst[j] = {
author:currentPlaylist[i].author,
description:currentPlaylist[i].description,
duration:currentPlaylist[i].duration,
file:currentPlaylist[i].file,
link:currentPlaylist[i].link,
image:currentPlaylist[i].image,
start:currentPlaylist[i].start,
title:currentPlaylist[i].title,
type:currentPlaylist[i].type
}
//j++;
//}
}
if(lst.length > 0) { player.sendEvent('LOAD', lst); }
} */
//createPlayer(theFileLoad,'false');
//printPlaylistData();
player.sendEvent('STOP');
player.sendEvent('LOAD', theFileLoad);
//playerReady('player1');
printPlaylistData();
//return false;
//printPlaylistData();
}
function createPlayer(theFile, theAutostart) {
//deletePlayer("placeholder1");
//printPlaylistData(theFile);
var flashvars = {
file:theFile,
autostart:theAutostart,
shuffle:false,
repeat:"list"
}
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
}
var attributes = {
id:"player1",
name:"player1"
}
swfobject.embedSWF("player.swf", "placeholder1", "400", "245", "9.0.115", false, flashvars, params, attributes);
}
function init() {
//Drag.init(document.getElementById("playerhandle"), document.getElementById("playerroot"));
//Drag.init(document.getElementById("listhandle"), document.getElementById("listroot"));
//document.getElementById("playerhandle").style.cursor = 'move';
//document.getElementById("listhandle").style.cursor = 'move';
createPlayer('playlist3.xml', false);
}
</script>
</head>
<body onLoad="init();">
<div id="txt" style="position:absolute; left:30px; top:30px">
<a href="http://www.jeroenwijering.com/?item=JW_FLV_Media_Player"> JW FLV Media Player</a><br><br>
with a customized playlist: <a href="playlist_mixmedia.xml">playlist_mixmedia.xml</a>
</div>
<div id="playerroot" style="position:absolute; left:50px; top:110px">
<div id="playerhandle">JW FLV Media Player</div>
<div id="wrapper">
<div id="placeholder1"></div>
</div>
</div>
<div id="listroot" style="position:absolute; left:450px; top:110px">
<div id="listhandle"> Custom Playlist</div>
<div class="playlistbox" align="left">
<div id="plstDat"></div>
</div>
</div>
<a href="javascript:loadCheckedPlaylistData('playlist.xml')">Play list 1 </a>
<a href="javascript:loadCheckedPlaylistData('playlist1.xml')">Play list 1 </a>
<a href="javascript:loadCheckedPlaylistData('playlist2.xml')">Play list 1 </a>
</body>
</html>
I can't find anything wrong with this code; it works perfectly for me:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en">
<head>
<title>JW FLV Media Player with Separate Playlist</title>
<style type="text/css">
body
{
padding: 0;
margin: 0;
font-size: 12px;
font-family: verdana,helvetica,arial;
background-color: #ffffff;
}
#playerroot
{
position: absolute;
top: 110px;
left: 50px;
width: 400px;
height: 265px;
border: #333 1px solid;
border-bottom: 0;
background-color: #f4f4f4;
z-index: 9999;
}
#listroot
{
position: absolute;
top: 110px;
left: 456px;
width: 400px;
height: 265px;
border: #333 1px solid;
background-color: #f4f4f4;
z-index: 2;
}
#playerhandle
{
width: 396px;
padding: 2px;
margin: 2px;
color: white;
background-color: #426300;
font-weight: bold;
}
#listhandle
{
width: 400px;
padding: 2px;
margin: 2px;
color: white;
background-color: #426300;
font-weight: bold;
}
#txt
{
position: absolute;
left: 50px;
top: 30px;
}
#links
{
position: absolute;
top: 89px;
left: 50px;
padding: 3px;
border: #333 1px solid;
background-color: #f4f4f4;
}
#link
{
width: 100px;
height: 20px;
display: inline;
}
.playinglo
{
font: 12px verdana,arial,helvetica,sans-serif;
color: #000000;
background-color: #c6ef74;
}
.playinghi
{
font: 12px verdana,arial,helvetica,sans-serif;
color: #000000;
background-color: #7bad00;
vertical-align: top;
text-align: left;
}
.playlistlo
{
font: 12px verdana,arial,helvetica,sans-serif;
color: #000000;
background-color: #7bad00;
vertical-align: top;
text-align: left;
}
.playlisthi
{
font: 12px verdana,arial,helvetica,sans-serif;
color: #000000;
background-color: #c6ef74;
}
.playlistbox
{
width: 404px;
height: 242px;
margin: 0;
border: #7bad00 1px solid;
overflow: auto;
}
</style>
<script type="text/javascript" src="swfobject-2.1.js"></script>
<script type="text/javascript">
var currentItem = -1;
var previousItem = -1;
var currentLength = 0;
var currentState = 'NONE';
var previousState = 'NONE';
var linkFlag = false;
var player = null;
function playerReady(thePlayer)
{
//alert(thePlayer);
player = document.getElementById(thePlayer.id);
addListeners()
printPlaylistData();
};
function addListeners()
{
if (player)
{
player.addControllerListener('ITEM', 'itemListener');
player.addModelListener('STATE', 'stateListener');
}
else
{
setTimeout("addListeners()", 100);
}
};
function itemListener(obj)
{
if (obj.index != currentItem)
{
previousItem = currentItem;
currentItem = obj.index;
setItemStyle(currentItem);
//alert("sdffsdfsd");
}
};
function stateListener(obj) //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
{
currentState = obj.newstate;
//previousState = obj.oldstate;
var tmp = document.getElementById("itm" + currentItem);
if((currentState != previousState) || (currentItem != previousItem))
{
previousState = currentState;
setItemStyle(currentItem);
}
};
function mover(obj, idx)
{
if (idx == currentItem)
{
obj.className = 'playinghi';
}
else
{
obj.className = 'playlisthi';
}
};
function mout(obj, idx)
{
linkFlag = false;
if(idx == currentItem)
{
obj.className = 'playinglo';
}
else
{
obj.className = 'playlistlo';
}
};
function setItemStyle(idx)
{
var count = getLength();
for(var i = 0; i < count; i++)
{
var tmp = document.getElementById("itm" + i);
if(tmp)
{
if(i == idx)
{
if(currentState == 'PLAYING')
{
tmp.className = 'playinglo';
}
//'playinghi';
else
{
tmp.className = 'playlisthi';
}
//'playinglo';
}
else
{
tmp.className = 'playlistlo';
}
}
}
};
function getLength()
{
currentLength = player.getPlaylist().length;
return(currentLength);
};
function printPlaylistData()
{
var plst = null;
//var currentPlaylist;
var tmp = document.getElementById("plstDat");
//tmp.innerHTML == "";
plst = player.getPlaylist();
if (plst)
{
//currentPlaylist = plst;
//alert("fsdfasdfasdf");
var txt = '<table cellPadding="2" width="380">';
for(var i in plst)
{
txt += '<tr><td><table width="380" id="itm' + i + '" onclick="player.sendEvent(\'ITEM\',' + i + ');" ';
txt += 'class="playlistlo" onmouseover="mover(this, ' + i + ')" onmouseout="mout(this, ' + i + ')">';
txt += '<tr><td><img src="' + plst[i].image + '" width="90" height="68" title="Click to Play"></td>';
txt += '<td width="276" valign=middle><p>';
txt += plst[i].title + '<br>';
txt += '<b>' + plst[i].author + '</b><br>';
txt += '<b>Duration ' + plst[i].duration + ' Mnts</b><br>';
txt += '<a href="' + plst[i].link + '" target="_self" title="' + plst[i].link + '"> more info</a><br>';
//txt += plst[i].description;
txt += '</p></td></tr></table></td></tr>';
}
txt += '</table>'; //alert(txt);
if(tmp)
{
tmp.innerHTML = txt;
}
}
else
{
setTimeout("printPlaylistData()", 100);
}
};
function loadCheckedPlaylistData(theFileLoad)
{
/*
if (currentPlaylist)
{
var j = 0;
var lst = new Array();
for(var i in currentPlaylist)
{
if(document.getElementById('cb' + i).checked)
{
lst[j] =
{
author: currentPlaylist[i].author,
description: currentPlaylist[i].description,
duration: currentPlaylist[i].duration,
file: currentPlaylist[i].file,
link: currentPlaylist[i].link,
image: currentPlaylist[i].image,
start: currentPlaylist[i].start,
title: currentPlaylist[i].title,
type: currentPlaylist[i].type
}
j++;
}
}
if(lst.length > 0)
{
player.sendEvent('LOAD', lst);
}
}
*/
//createPlayer(theFileLoad,'false');
//printPlaylistData();
player.sendEvent('STOP');
player.sendEvent('LOAD', theFileLoad);
//playerReady('player1');
printPlaylistData();
//return false;
//printPlaylistData();
};
//deletePlayer("placeholder1");
//printPlaylistData(theFile);
var flashvars =
{
file: 'playlist_mike.asx',
autostart: 'true',
shuffle: 'false',
repeat: 'list'
}
var params =
{
allowfullscreen: 'true',
allowscriptaccess: 'always'
}
var attributes =
{
id: 'player1',
name: 'player1'
}
swfobject.embedSWF("player-4.3.91.swf", "placeholder1", "400", "245", "9.0.115", false, flashvars, params, attributes);
/*
function init()
{
//Drag.init(document.getElementById("playerhandle"), document.getElementById("playerroot"));
//Drag.init(document.getElementById("listhandle"), document.getElementById("listroot"));
//document.getElementById("playerhandle").style.cursor = 'move';
//document.getElementById("listhandle").style.cursor = 'move';
createPlayer('playlist3.xml', false);
};
*/
</script>
</head>
<body>
<div id="txt">
<a href="http://www.jeroenwijering.com/?item=JW_FLV_Media_Player">JW FLV Media Player</a>
<br />
<br />
With a customized playlist:
<a href="playlist_mixmedia.xml">playlist_mixmedia.xml</a>
</div>
<div id="playerroot">
<div id="playerhandle">
JW FLV Media Player
</div>
<div id="wrapper">
<div id="placeholder1">
</div>
</div>
</div>
<div id="listroot">
<div id="listhandle">
Custom Playlist
</div>
<div class="playlistbox" align="left">
<div id="plstDat">
</div>
</div>
</div>
<div id="links">
<a id="link" href="javascript:loadCheckedPlaylistData('playlist_mike_01.asx')">LOAD Playlist 1</a>
<a id="link" href="javascript:loadCheckedPlaylistData('playlist_mike_02.asx')">LOAD Playlist 2</a>
<a id="link" href="javascript:loadCheckedPlaylistData('playlist_mike_03.asx')">LOAD Playlist 3</a>
</div>
</body>
</html>
Looks nice also! :D
Nice job andersen. :)