flex播放外部传入的flv地址视频
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
addedToStage="init();"
height="320"
width="590"
backgroundColor="0x000000"
horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<mx:Style source="style/FlvPlayerCss.css"/>
<mx:Script>
<![CDATA[
import flash.display.StageDisplayState;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import mx.collections.ArrayCollection;
import mx.effects.Glow;
import mx.events.SliderEvent;
import mx.events.VideoEvent;
import mx.rpc.events.ResultEvent;
private var timer:Timer;
private var isplaying:Boolean=true;
[Bindable]
private var video_url:String="assets/1.flv";
private var isAdd:Boolean=false; //标识音量
private var tempTimer:Timer=new Timer(1500,1);
//延迟0.05秒左右
private function init():void
{
timer=new Timer(1000, 1);
timer.addEventListener(TimerEvent.TIMER, PlayVideo);
timer.start();
}
//延迟5秒后让视频开始播放
private function PlayVideo(event:TimerEvent):void
{
//播放媒体文件。如果文件尚未加载,则会加载它。当回放暂停、停止或控件正在播放时,可以调用此方法。
//要流式播放来自摄像机的视频,请调用 attachCamera() 方法,而不是调用 play() 方法
flv_video.play();
//playhead_update事件在视频正在播放时继续分派。事件之间的间隔(以毫秒为单位)由 playheadUpdateInterval 属性指定,默认为 250 毫秒。
//视频处于暂停或停止状态时,不分派此事件。
flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler); //即每间隔250毫秒调用一次progressHandler方法
}
private var position:Number;
//视屏播放时的进度条(HSlider控件)
private function progressHandler(event:VideoEvent):void
{
hs.value=flv_video.playheadTime; //开始设置进度条值
//如果新的播放头位置小于 0 或为 NaN,则控件将引发异常。当播放头时间为0时即刚开始里设置属性
if (flv_video.playheadTime == 0)
{
flv_video.pause();
}
}
//HSlider控件被触发
private function thumbChanges(event:SliderEvent):void
{
flv_video.playheadTime=hs.value;
}
//格式化 播放时间的显示方式
private function formatTimes(value:int):String
{
var result:String=(value % 60).toString();
if (result.length == 1)
{
result=Math.floor(value / 60).toString() + ":0" + result;
}
else
{
result=Math.floor(value / 60).toString() + ":" + result;
}
return result;
}
//鼠标悬浮时的外发光效果
private function mouseOverHandler(evt:MouseEvent):void
{
//Glow是 flex中用来展示外发光效果的对象
var glow:Glow=new Glow();
//水平的初始发光距离
glow.blurXFrom=0;
//水平发光结束时的距离
glow.blurXTo=50;
glow.blurYFrom=0;
glow.blurYTo=50;
//发光的持续时间,是以毫秒为单位的
glow.duration=800;
//发光时的颜色
glow.color=0xffffff;
//发光形式 true:内发光 false:外发光
//指定为 '谁'提供发光服务
glow.target=evt.currentTarget;
glow.stop();
glow.play();
}
private function doProgressMD():void
{
flv_video.removeEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
}
private function doProgressMU():void
{
tempTimer.addEventListener(TimerEvent.TIMER,doTempTimer);
tempTimer.start();
}
private function doTempTimer(event:TimerEvent):void{
flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
}
//播放Flv视屏的操作
private function flvplay(event:Event):void
{
if (isplaying)
{
flv_video.pause();
}
else
{
flv_video.play();
}
isplaying=!isplaying;
}
]]>
</mx:Script>
<mx:Fade id="fadeOut"
duration="10000"
alphaFrom="1.0"
alphaTo="0.0"/>
<mx:VideoDisplay id="flv_video" x="-53" y="-50" width="689" height="420" bufferTime="1"
buttonMode="true" click="flvplay(event)"
useHandCursor="true" source="{video_url}"/>
<mx:HSlider id="hs"
width="568"
height="20"
styleName="progressBar"
allowTrackClick="true"
showTrackHighlight="true"
mouseDown="doProgressMD()"
mouseUp="doProgressMU();"
buttonMode="true"
useHandCursor="true"
maximum="{flv_video.totalTime}"
minimum="0"
x="12"
y="294"
showDataTip="false"
change="thumbChanges(event)"
mouseOver="mouseOverHandler(event)"/>
</mx:Application>
html端:
另外注意火狐里需要在<embed>标签里加参数
<!-- saved from url=(0014)about:internet -->
<html lang="en">
<body scroll="no">
<script language="JavaScript" type="text/javascript">
<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);
// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if ( hasProductInstall && !hasRequestedVersion ) {
// DO NOT MODIFY THE FOLLOWING FOUR LINES
// Location visited after installation is complete if installation is required
var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
var MMredirectURL = window.location;
document.title = document.title.slice(0, 47) + " - Flash Player Installation";
var MMdoctitle = document.title;
AC_FL_RunContent(
"src", "playerProductInstall",
"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
"width", "590",
"height", "320",
"align", "middle",
"id", "FlvPlayer3",
"quality", "high",
"wmode", "opaque",
"name", "FlvPlayer3",
"allowFullScreen","true",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else if (hasRequestedVersion) {
// if we've detected an acceptable version
// embed the Flash Content SWF when all tests are passed
AC_FL_RunContent(
"src", "FlvPlayer3",
"width", "590",
"height", "320",
"align", "middle",
"id", "FlvPlayer3",
"quality", "high",
"bgcolor", "#ffffff",
"name", "FlvPlayer3",
"allowFullScreen","true",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else { // flash is too old or we can't detect the plugin
var alternateContent = 'Alternate HTML content should be placed here. '
+ 'This content requires the Adobe Flash Player. '
+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
document.write(alternateContent); // insert non-flash content
}
// -->
</script>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="FlvPlayer3" width="590" height="320"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="FlvPlayer3.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="FlashVars" value="myVideoSource=assets/3.flv" /> <param name="allowScriptAccess" value="sameDomain" />
<embed src="FlvPlayer3.swf" quality="high" bgcolor="#ffffff"
width="590" height="320" name="FlvPlayer3" align="middle"
play="true"
loop="false"
quality="high"
FlashVars="myVideoSource=assets/3.flv"
"allowFullScreen","true"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed> </object>
</body>
</html>