Connect PHP and Flex Player
I'm using Flex Player component on a localhost. The FLV video files are stored in bin-debug/Video Source. The PHP code for the video is:
$id = $_GET["id"];
$media = getDirectoryList("bin-debug/Video Source");
if($media[$id] != null){
$video = $media[$id];
$fileName = "bin-debug/Video Source/".$video;
$pieces = explode(".", $video);
$video = $pieces[0];
}
The player is generated on the HTML page via javascript where createPlayer(); writes FlexPlayer.swf on the page between object tags
<script type="text/javascript">
createPlayer();
</script>
My question is where and how to put the $video
variable to dynamically load video in this FlexPlayer.swf. CreatePlayer() is:
function createPlayer("<?php echo $fileName; ?>"){
document.writeln("<div id="player">");
document.writeln("<object width="489" height="414">");
document.writeln("<param name="player" value="bin-debug/FlexPlayer.swf">");
document.writeln("<embed src="bin-debug/FlexPlayer.swf" name="player" width="489" height="414">");
document.writeln("</embed>");
document.writeln("</object>");
document.writeln("</div>");
}
You can pass variables to your swf file using flashVars properties
Without seeing the code for createPlayer()
I cannot give you specific details about how you should do this.
Assuming that your video player is showing one video only and the id for that video is passed to the web page using POST or GET then pass the file name using flashVars. For this a recommend using swfobject. Something like this should do the trick:
webpage.php
<?php
//your stuff
$video = phpFunctionToGetTheFilePath($id);
//more stuff
?>
<html>
<head>
<!-- head stuff,the javascript function declaration to display the video player -->
<script type="text/javascript">
createPlayer("<?php echo $video; ?>");//the function's argument is the filename to pass as flashvars
</script>
</head>
<body>
<!-- your player container somewhere here -->
</body>
</html>
If you want to change the video displayed without refreshing the page then consider using AJAX to get the file name or just pass the id to the flash player and do the work in flex (flex gets the id and retrieves the filename from the server using XML or amf)
链接地址: http://www.djcxy.com/p/52624.html上一篇: nodejs vs Ubuntu 12.04上的节点
下一篇: 连接PHP和Flex Player