用Flex4 开发的Flv播放器
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
backgroundGradientColors="[#F1F2F6,#FBFCFF]" creationComplete="flv_video.volume=0.2" applicationComplete="getPosition();init();initBuffer()"
backgroundGradientAlphas="[1.0,1.0]" width="500" height="400"
verticalScrollPolicy="off" horizontalScrollPolicy="off" alpha="0.99" color="#F6FDFF" borderColor="#414344">
<mx:Script source="com/uuwapps/flv/Flv.as"/> <!-- 播放器事件处理类 -->
<mx:Style>
ToolTip {
backgroundAlpha: 1.0;
backgroundColor: haloBlue;
fontWeight: bold;
color: white;
}
HSlider {
thumbSkin: Embed(source="resources/gif/hsilder.gif");
dataTipPlacement: right;
dataTipOffset: 0;
showTrackHighlight: true;
labelStyleName: MyLabel;
dataTipStyleName: MyDataTip;
}
.MyLabel{
fontFamily: ArialEmbedded;
fontSize: 20;
fontWeight: normal;
}
.MyDataTip {
backgroundAlpha: 1.0;
backgroundColor: haloBlue;
color: white;
cornerRadius: 10;
fontWeight: bold;
letterSpacing: 1;
}
</mx:Style>
<mx:Script>
<![CDATA[
//程序初始化的时候调整加载进度条的绝对位置
private function getPosition():void
{
logo.stage.frameRate=7;//控制控件的帧的频率
progressBar.x = hs.x+9.3;
progressBar.y = hs.y+362;
}
private var timer:Timer;
//延迟5秒左右
private function initBuffer():void
{
flv_video.bufferTime = 4.55; //缓冲时间
timer= new Timer(5800,1);
timer.addEventListener(TimerEvent.TIMER,autoPlay);
timer.start();
}
//延迟5秒后让视频开始播放
private function autoPlay(event:TimerEvent):void
{
logo.visible=false;
pro.visible =false;
flv_video.play();
progressBar.source=flv_video;
flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE,progressHandler);
}
]]>
</mx:Script>
<mx:Fade id="fadeOut" duration="10000" alphaFrom="1.0" alphaTo="0.0"/>
<mx:CheckBox id="out" x="319" y="131" visible="false" selected="false"/>
<!--视屏容器 -->
<mx:VideoDisplay id="flv_video" width="502" height="376" backgroundColor="#F4F4F6"
source="{video_url}" useHandCursor="true" buttonMode="true" mouseChildren="false" autoPlay="true"
click="flvplay(event)" mouSEOut="out.selected = false;" mouSEOver="out.selected = true;showAndHide.visible = false;" verticalCenter="-12" right="0" borderColor="#38383A"/>
<mx:ProgressBar x="0" y="0" height="376" width="500" id="pro"
mode="manual" mouSEOver="out.selected = true;showAndHide.visible = false" labelPlacement="center" themeColor="#606063" color="#F4F4F6" borderColor="#505052"/>
<mx:SWFLoader id="logo" y="135" width="163" height="82.3" source="@Embed('resources/gif/flv4.swf')" horizontalCenter="22"/>
<mx:Label x="10" y="10" text="联讯证券" width="72" color="#BDC3C5"/>
<mx:HBox width="484" id="showAndHide" visible="{out.selected}" hideEffect="{fadeOut}"
horizontalCenter="0" verticalCenter="166" horizontalGap="10" verticalScrollPolicy="off" horizontalScrollPolicy="off">
<!--播放视屏的按钮 -->
<mx:Image height="20" source="@Embed('resources/gif/over.gif')" id="play_btn"
click="flvplay(event)" mouSEOver="mouSEOverHandler(event)"
useHandCursor="true" buttonMode="true" mouseChildren="false"/>
<!--显示播放时的时间 -->
<mx:Label text="{formatTimes(flv_video.playheadTime)}" id="playTime" paddingRight="12"
useHandCursor="true" buttonMode="true" mouseChildren="false" width="60" color="#DBDDDE"/>
<!--播放进度控制器 -->
<mx:HSlider width="265" id="hs" showDataTip="false" height="15"
useHandCursor="true" buttonMode="true"
change="thumbChanges(event)"
minimum="0" maximum="{flv_video.totalTime}"
sliderThumbClass="{FlexibleSliderThumb}"/><!--FlexibleSliderThumb;改变Hsilder默认样式的类-->
<!-- 显示总时间-->
<mx:Label text="{formatTimes(flv_video.totalTime)}" width="53" buttonMode="true"
mouseChildren="false" paddingLeft="5" color="#CFD4D5"/>
<!-- 音量控制器-->
<mx:Image width="14" height="15" source="@Embed('resources/gif/laba.gif')"
click="mouSEOverHandler(event);sound_thumbChanges()"
useHandCursor="true" buttonMode="true"/>
<!-- 全屏事件触发按钮-->
<mx:Image height="15" width="16" id="fullScreen" source="@Embed('resources/gif/full.gif')"
useHandCursor="true" buttonMode="true" mouseChildren="false"
mouSEOver="mouSEOverHandler(event)" click="display()" />
</mx:HBox>
<mx:ProgressBar x="124" y="252" height="2.3" id="progressBar" width="265" mode="event"
minimum="0" maximum="100" barColor="#009dff"
trackColors="[white,haloSilver]" visible="{out.selected}" hideEffect="{fadeOut}"/>
</mx:Application>
import flash.display.StageDisplayState;
import flash.events.Event;
import mx.collections.ArrayCollection;
import mx.effects.Glow;
import mx.events.SliderEvent;
import mx.events.VideoEvent;
import mx.rpc.events.ResultEvent;
[Embed(source="resources/gif/play.gif")]
[Bindable]
public var ico_play:Class;
[Embed(source="resources/gif/over.gif")]
[Bindable]
public var ico_stop:Class;
private var isplaying:Boolean=false;
[Bindable]
private var video_url:String ="";
private var playPosition:Number; //显示影片播放进度
private var soundPosition:Number = 0.00; //显示声音(声音大的话对应的HSlider的X坐标正方向的进度会被显示的长)
private var isFullScreen:Boolean = false; //是否是全屏
private var isAdd:Boolean = false; //标识音量
//播放Flv视屏的操作
private function flvplay(event:Event):void
{
if (isplaying){
play_btn.source=ico_play;
flv_video.pause();
}
else{
play_btn.source=ico_stop;
flv_video.play();
}
isplaying=!isplaying;
}
//视屏播放时的进度条(HSlider控件)
private function progressHandler(event:VideoEvent):void
{
hs.value = flv_video.playheadTime;
if(flv_video.playheadTime == 0)
{
flv_video.pause();
play_btn.source=ico_play;
}
}
//HSlider控件被触发
private function thumbChanges(event:SliderEvent):void
{
flv_video.playheadTime = hs.value;
playPosition=hs.value;
}
//改变声音的大小时对应的HSlider控件的显示程度(音量) 循环判断
private function sound_thumbChanges():void
{
if(!isAdd && soundPosition <1) //加音量
{
soundPosition = soundPosition+0.05;
flv_video.volume = soundPosition;
}
else if(isAdd) //减音量
{
soundPosition = soundPosition-0.05;
flv_video.volume = soundPosition;
if(flv_video.volume == 0)
{
isAdd = false;
}
}
else if(soundPosition == 1 || !isAdd )
{
isAdd = true;
soundPosition = soundPosition-0.05;
flv_video.volume = soundPosition;
}
}
//格式化 播放时间的显示方式
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 display():void{
if(!isFullScreen){
stage.fullScreenSourceRect = new Rectangle(flv_video.x,flv_video.y,flv_video.width,flv_video.height);
stage.displayState = StageDisplayState.FULL_SCREEN;
isFullScreen = true;
}
else{
stage.displayState = StageDisplayState.NORMAL;
isFullScreen = false;
}
}
//鼠标悬浮时的外发光效果
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 =1000;
//发光时的颜色
glow.color=0xffffff;
//发光形式 true:内发光 false:外发光
glow.inner = false;
glow.strength = 25;
//指定为 '谁'提供发光服务
glow.target=evt.currentTarget;
glow.stop();
glow.play();
}
//动态加载视频地址
private function init():void {
//获取外部传给SWF文件的参数值对
var obj:Object = stage.loaderInfo.parameters;
if(obj.address != null) {
video_url =obj.address;
}
}
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。