Welcome to WebmasterWorld Guest from 54.147.63.124

Forum Moderators: open

Message Too Old, No Replies

flash movie player using php variable

     
2:31 pm on Sep 8, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:June 7, 2007
posts:82
votes: 0


Hey all

I need a flash video player to use on a website, but I need it to be able to read the flv video location from a database variable. So using some PHP and a MySQL database I'm going to end up with something equivalent to...

$filename = 'videos/my-video.flv';

... and I will then want to be able to call a flash video player that can read in my video location variable and show up on the website all skinned out (well just the basic flash player skin).

Can anybody help me out with some advice as to how I would go about doing this?

Thanks in advance.
4:47 pm on Sept 8, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


You're almost there. :-)

Most Flash players will import video via external XML files. All you need to do is output valid XML from your PHP. For example, let's say your embed code is using SWFObject (which it should) and you *normally* point to the video list like this.



<script type="text/javascript" src="/js/swfobject.js"></script>
<script type="text/javascript">
window.onload = function() {
if (document.getElementById('video-canvas')) {
var video = new SWFObject('\/flv\/myplayer.swf', 'video-embed', '495', '420', '6', '#ffffff');
video.addParam("wmode", "transparent");
video.addVariable("playlist", "\/somedirectory\/playlist.xml");
video.write('video-canvas');
}
};
</script>


You'd just change the bolded line to
video.addVariable("playlist", "\/somedirectory\/your-script.php");

which would output valid XML. Most players accept movie, title, caption, and the like so you'd do

header("content-type:text/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<movies>";

Query your database, get full url, caption, etc . . .

while ($row=mysql_fetch_array($result)) {
$movie = $row['movie'];
$title = $row['title'];
$cap = $row['caption'];
echo "<movie url=\"$movie\" movietitle=\"$title\" moviecaption=\"$cap\"/>";
}

Then don't forget to close . . .

echo "</movies>";

It will vary from player to player, but that's how you'd most likely want to do it.