最近在做一个页面,其中有实现播放flv格式流媒体(不知道是否可以称为流媒体)的一块。
于是乎,查了之前作过的未发布的视频网页面(2年前的事了),于是写了个测试播放的。当然,也参考了56.com的js运行状态代码(通过Firefox DOM Inspector参考了56.com播放页面的JS运行状态)和Dreamweaver8里插入Flash视频。
<
object id =" MyFLVPlayer "
classid
="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase
="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
width
="503"
height
="416"
>
<
param
name
="movie"
value
="FLVPlayer_Progressive.swf"
/>
<
param
name
="salign"
value
="lt"
/>
<
param
name
="quality"
value
="high"
/>
<
param
name
="scale"
value
="noscale"
/>
<
param
name
="FlashVars"
value
="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=a8eb4f22dea99f5dfad3bcbb7b03cbd29582185&autoPlay=true&autoRewind=true"
/>
<
embed
src
="FLVPlayer_Progressive.swf"
flashvars
="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=a8eb4f22dea99f5dfad3bcbb7b03cbd29582185&autoPlay=true&autoRewind=true"
quality
="high"
scale
="noscale"
width
="503"
height
="416"
name
="FLVPlayer"
salign
="LT"
type
="application/x-shockwave-flash"
pluginspage
="http://www.macromedia.com/go/getflashplayer"
/>
</
object
>
轻松实现了web page里的flv格式视频播放。接下来问题出现了。
一.FLV文件路径的动态绑定
那么从数据库里读文件,动态绑定播放也容易。比如PHP; Database:test, Table:tvideo (有VIDEOPATH属性)
<
div
>
{
?
php
//
connect db
if
(
!
(
$conn
=
mysql_connect
(
"
localhost
"
,
"
root
"
,
""
)))
echo
"
database server connection failed
"
;
//
select db
if
(
!
mysql_select_db
(
"
test
"
,
$conn
))
echo
"
no db 'test' existed
"
;
else
{
$sql
=
"
select * from tvideo order by id desc limit 10
"
;
//
display 10 data items
$result
=
mysql_query
(
$sql
,
$conn
);
while
(
$row
=
mysql_fetch_assoc
(
$result
)){
$videopath
=
"
streamName=
"
$row
[
"
VIDEOPATH
"
];
echo
"<tr><td>
<object id='MyFLVPlayer' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='503' height='416'> <param name='movie' value='FLVPlayer.swf' /> <param name='salign' value='lt' /> <param name='quality' value='high' /> <param name='scale' value='noscale' /> <param name='FlashVars' value='&MM_ComponentVersion=1&skinName=Clear_Skin_1&$videopath&autoPlay=true&autoRewind=true' /> <embed src='FLVPlayer.swf' flashvars='&MM_ComponentVersion=1&skinName=Clear_Skin_1&$videopath&autoPlay=true&autoRewind=true' quality='high' scale='noscale' width='503' height='416' name='FLVPlayer' salign='LT' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /> </object></td></tr>
"
; } }
?>
</
div
>
//
...html code
二. 指定播放某个视频
上述代码会在页面播放10个FLV视频,如果数据库里存在足够多的视频的话。但是这极不符合用户习惯。所以作如此设计:一边是视频列表,一边是一个播放器;每点击一个视频,就播放之,不是同时播放这么多了。
那么,这就要传参数给Flash控件FlashVars参数。通过JavaScript操作,可以获得FlashVars,但是问题就出在这里:测试可以看到读出来的FlashVars无值;而给FlashVars赋值也不成功,JS如下:
<
script type
=
"
text/JavaScript
"
>
var
flashvars
=
document.MyFLVPlayer.FlashVars;
//
没有内容
//
alert(flashvars); //test to show null
var
videopath
=
"
testflv.flv
"
; flashvars
=
"
streamName="
"
+
videopath
+
'
"
'
;
//
attempt to assign videopath to FlashVars
/*
if
(
!
document.MyFLVPlayer.FlashVars) alert(
"
test to show assignment failed
"
);
else
alert(
"
test to show assignment succeed
"
);*/
</
script
>
三.Flash OBJECT and EMBED tag syntax and SWFObject
thanks to (1)IE"单击以激活并使用此控件"官方补丁发布 http://www.cenfun.com/blog/article.asp?id=96 (另外,该blog的日历极具创意) (2)Macromedia Flash OBJECT and EMBED tag syntax http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_4150&sliceId=2 (3)SWFObject: Javascript Flash Player detection and embed script http://blog.deconcept.com/swfobject/
<未完... ...>