网页中嵌入Flash播放器

1. 需要准备swfobject.js和flvplayer.swf文件,请看附件

2. flvplayer.swf有两种播放形式,一种是播放单个文件,一种是选择列表中的文件进行播放
   
    a. 播放单个文件只需在网页中嵌入如下代码:
<script type="text/javascript" src="../../js/swfobject.js"></script>
<p id="player_single"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
	var s1 = new SWFObject("../../player/flvplayer.swf","single","300","170","7");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("file","../../video/video/BadDay.flv");
	s1.addVariable("image","../../../video/image/preview.jpg");
	s1.addVariable("width","300");
	s1.addVariable("height","170");
	s1.write("player_single");
</script>


   b. 播放列表还需要一个playlist.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
	<trackList>

		<track>
			<title>Afraid</title>
			<creator>Jeroen Wijering</creator>
			<location>../../video/video/video.flv</location>
		</track>
		
		<track>
			<title>xiaoxuntong ad</title>
			<creator>zhup</creator>
			<location>../../video/video/ad.flv</location>
		</track>

		<track>
			<title>Afraid (again)</title>
			<creator>Jeroen Wijering</creator>
			<location>../../video/video/video.flv</location>
		</track>

		<track>
			<title>Afraid (once again)</title>
			<creator>Jeroen Wijering</creator>
			<location>../../video/video/video.flv</location>
			<info>http://www.jeroenwijering.com/</info>
		</track>

	</trackList>
</playlist>


在网页中嵌入如下代码:
<script type="text/javascript" src="../../js/swfobject.js"></script>

<p id="player_list"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
	var s2 = new SWFObject("../../player/flvplayer.swf","playlist","300","312","7");
	s2.addParam("allowfullscreen","true");
	s2.addVariable("file","../../../video/playlist/playlist.xml");
	s2.addVariable("displayheight","200");
	s2.addVariable("backcolor","0x000000");
	s2.addVariable("frontcolor","0xCCCCCC");
	s2.addVariable("lightcolor","0x557722");
	s2.addVariable("width","300");
	s2.addVariable("height","312");
	s2.write("player_list");
</script>



特别需要注意的是swfobject.js、SWFObject中的file和image参数、flvplayer.swf的路径,假如路径不对是播放不了Flash文件的。

(1)swfobject.js、SWFObject中image参数、flvplayer.swf的路径是相对于要嵌入播放器的网页的相对路径
(2)SWFObject中file参数是相对于flvplayer.swf的相对路径
(3)代码中的..表示上一层目录
(4)只要顺着路径可以找到上述提到的几个文件,无论网页放在哪个位置,Flash文件都可以播放

你可能感兴趣的:(xml,Flash)