Jan. 15, 2009Jordan
Alright, let me word my post a little differently. Hopefully I can find some help that way.
How can I have call a video to play based on its "title" rather than its item position in the XML document with the getQueryParamValue?
I currently need the link by a number for one part of my site but would like to have the additional option to call by the title.
My current code based off of another post here:
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var player = null;
var playItem = null;
var file = null;
if(!(playItem = swfobject.getQueryParamValue('item')))
{
// default is first item (array counting starts at 0)
playItem = 0;
}
if(!(file = swfobject.getQueryParamValue('playlist')))
{
// default playlist
file = 'playlist.xml';
}
//alert('Play Item: ' + playItem + '\nFile: ' + file);
function playerReady(obj)
{
player = document.getElementById(obj.id);
playAway();
};
// start the player on the query parameter item
function playAway()
{
if(player)
{
//alert('playAway:\nPlayer: ' + player.id + '\nplayAway - playItem:' + playItem);
setTimeout("player.sendEvent('ITEM', playItem)", 200);
setTimeout("player.sendEvent('PLAY', 'true')", 400);
}
else
{
setTimeout("playAway()", 200);
}
};
</script>
<script type="text/javascript">
var flashvars = {
file:file,
autostart:"true",
shuffle:"false",
playlistsize:"200",
playlist:"bottom",
skin:"stylish/modieus.swf",
frontcolor:"cccccc",
lightcolor:"6e1f84",
backcolor:"111111",
repeat:"list"
//logo:"logo_overlay.png"
}
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
}
var attributes = {
id:"player1",
name:"player1"
}
swfobject.embedSWF("player.swf", "placeholder1", "570", "570", "9.0.115", false, flashvars, params, attributes);
</script>
</head>
<body>
<div id="wrapper">
<div id="placeholder1">
<a href="http://www.macromedia.com/go/getflashplayer">Get flash</a> to see this player.
</div>
</div>
</body>
Jan. 15, 2009noMind
Use this code: removeIt(removeItTitle) from this thread, except instead of removing the title, play it. You will have to update the code for teh v4.x players.
http://www.longtailvideo.com/support/forum/JavaScript-Interaction/9232/remove-item-by-file-title
Jan. 15, 2009Jordan
Yes, I saw that code but I didn't know how to update it to the v4.x players. Can you help out with that?
Thanks,
Jordan
Jan. 16, 2009noMind
@Jordan,
The v4.x player code would be:
// play item by Title
function playIt(playItem)
{
var playlist = player.getPlaylist();
for(var j in playlist)
{
if(playItem == playlist[j].title)
{
player.sendEvent('ITEM', j);
}
}
};
You can see it in context here for a day or two:
http://willswonders.myip.org:8085/php/Jordan.html
Add a few songs by clicking on the first row of buttons; make sure "Song 3" is one of them.
Then click [Play by Title: "Song 3"]
Jan. 19, 2009Jordan
Awesome! I will give this a try.
Jan. 21, 2009Jordan
@noMind,
Ok, as you can tell I am new to the JW Player so I am struggling a bit. I can't figure out how to integrate the title code into my code to work properly. Could you help?
Thanks!!!!
Jan. 21, 2009lefTy
Did you look at the demo code to see the function in context?
Post your test page or a link to it and I'll help you integrate the playIt() function.
Jan. 21, 2009Jordan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>University of Wisconsin-Stevens Point :: Video Player</title>
<style type="text/css">
body {
padding:0;
margin:0;
}
</style>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var player = null;
var playItem = null;
var file = null;
var id = null;
if(!(playItem = swfobject.getQueryParamValue('item')))
{
// default is first item (array counting starts at 0)
playItem = 0;
}
if(!(file = swfobject.getQueryParamValue('playlist')))
{
// default playlist
file = 'playlist.xml';
}
if(!(id = swfobject.getQueryParamValue('id')))
{
// default is first item (array counting starts at 0)
id = null;
}
//alert('Play Item: ' + playItem + '\nFile: ' + file);
function playerReady(obj)
{
player = document.getElementById(obj.id);
playAway();
};
// play item by Title
function playIt(id)
{
var playlist = player.getPlaylist();
for(var j in playlist)
{
if(id == playlist[j].title)
{
player.sendEvent('ITEM', j);
}
}
};
// start the player on the query parameter item
function playAway()
{
if(id == null)
{
//alert('playAway:\nPlayer: ' + player.id + '\nplayAway - playItem:' + playItem);
setTimeout("player.sendEvent('ITEM', playItem)", 200);
setTimeout("player.sendEvent('PLAY', 'true')", 400);
}
else
{
playIt(id);
//setTimeout("playAway()", 200);
}
};
</script>
<script type="text/javascript">
var flashvars = {
file:file,
autostart:"true",
shuffle:"false",
playlistsize:"200",
playlist:"bottom",
skin:"stylish/modieus.swf",
frontcolor:"cccccc",
lightcolor:"6e1f84",
backcolor:"111111",
repeat:"list"
//logo:"logo_overlay.png"
}
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
}
var attributes = {
id:"player1",
name:"player1"
}
swfobject.embedSWF("player.swf", "placeholder1", "570", "570", "9.0.115", false, flashvars, params, attributes);
</script>
</head>
<body>
<div id="wrapper">
<div id="placeholder1">
<a href="http://www.macromedia.com/go/getflashplayer">Get flash</a> to see this player.
</div>
</div>
</body>
</html>
Jan. 21, 2009lefTy
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- call with: http://www.mydomain.com/Jordan-2.html?&id=Doing My Time&item=&playlist=playlist.xml -->
<!-- call with: http://www.mydomain.com/Jordan-2.html?&id=&item=3&playlist=playlist.xml -->
<title>University of Wisconsin-Stevens Point :: Video Player</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
body
{
padding: 0;
margin: 0;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>
<script type="text/javascript">
var player = null;
var playItem = null;
var file = null;
var id = null;
if(!(playItem = swfobject.getQueryParamValue('item')))
{
//...default is first item (array counting starts at 0)
playItem = 0;
}
if(!(file = swfobject.getQueryParamValue('playlist')))
{
// default playlist
file = 'playlist.xml';
}
if(!(id = swfobject.getQueryParamValue('id')))
{
//...default is first item
id = null;
}
//alert('Play Item: ' + playItem + '\nFile: ' + file + '\nID (Title): ' + id);
function playerReady(obj)
{
player = document.getElementById(obj.id);
playAway();
};
//...start the player on the query parameter item
function playAway()
{
if(id == null)
{
//alert('playAway:\nplayAway - playItem:' + playItem);
setTimeout("player.sendEvent('ITEM', playItem)", 200);
setTimeout("player.sendEvent('PLAY', 'true')", 400);
}
else
{
playIt(id);
//setTimeout("playAway()", 200);
}
};
//...start the player on the play item by Title
function playIt(id)
{
var title = unescape(id);
var playlist = player.getPlaylist();
for(var j in playlist)
{
//alert(playlist[j].title);
if(title == playlist[j].title)
{
//alert('playIt:\nTitle:' + title + '\nPlaylist Title: ' + playlist[j].title + '\nIndex: ' + j);
player.sendEvent('ITEM', j);
break;
}
}
};
</script>
<script type="text/javascript">
var flashvars =
{
file: file,
autostart: 'true',
shuffle: 'false',
playlist: 'bottom',
playlistsize: '200',
skin: 'stylish/modieus.swf',
frontcolor: 'cccccc',
lightcolor: '6e1f84',
backcolor: '111111',
repeat: 'list'
//logo: 'logo_overlay.png'
};
var params =
{
allowfullscreen: 'true',
allowscriptaccess: 'always'
};
var attributes =
{
id: 'player1',
name: 'player1'
};
swfobject.embedSWF('player-4.4.135.swf', 'placeholder1', '570', '570', '9.0.124', false, flashvars, params, attributes);
</script>
</head>
<body>
<div id="wrapper">
<div id="placeholder1">
<a href="http://www.macromedia.com/go/getflashplayer">Get flash</a> to see this player.
</div>
</div>
</body>
</html>
Jan. 22, 2009Jordan
Awesome, thank you, thank you, Thank You!!!
Jan. 22, 2009lefTy
yer welcome!
Aug. 27, 2009OLEG
to: lefTy
Wow!!! Thanks a lot for your code!
It took me 3 days to find the solution for this!!!
REALLY THANK YOU!
Aug. 27, 2009lost
This is a little more up-to-date code:
http://willswonders.myip.org:8074/Simple_PlayQueryItem.html?file=playlist_songs.xml&item=9&time=10
Also:
http://willswonders.myip.org:8074/calledpage_file.html
http://willswonders.myip.org:8074/calledpage_item.html
http://willswonders.myip.org:8074/calledpage_title.html
Sep. 02, 2009OLEG
Thank you lost.
After my last post i had a problem, that i had to refresh the page after i call it with title, or it just loaded the first video in the playlist.
Your callpage_title script helped me a lot.
Thank you!!!
Sep. 02, 2009lost
@OLEG,
You're welcome.
Good Luck!
Oct. 28, 2009Terry McDougal
http://ocf.mcddesign.com/help_system/js/OCF_Help-call_from_URL.html?&id=&item=1&playlist=playlist.xml
Always plays video list item 0 - the URL's above from lost are no longer available. Using ID is the same.
Oct. 30, 2009AchtugBaby
@Terry
Check that you are using <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>. I had a similar problem until I did so.
Nov. 04, 2009Terry McDougal
OK I have most of this working now. According to the code I can call a playlist with the URL: &playlist=playlist.xml but that does not seem to work. I can call the "item" with the URL if I add the location of the playlist to the player code.
URL to my playlist: http://ocf.mcddesign.com/help_system/js/playlist.xml
URL to the player:
http://ocf.mcddesign.com/help_system/js/OCF_Help-call_from_URL-1.html?playlist=playlist.xml&item=3
Nov. 09, 2009Terry McDougal
Removed
Here are some helpful links to learn more about the JW Player™:
Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!
If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.