当前位置:文档之家› flex视频播放器(支持rtmp协议)开发代码

flex视频播放器(支持rtmp协议)开发代码

Flex视频播放器(支持rtmp协议)开发代码

开发工具:flash builder4.5 + red5服务器

建议参考之前阶段代码:

(1)flex视频播放器开发初级阶段代码:/detail/ll_jj_yy/

(2)支持rtmp协议,播放red5服务器上的flv视频文件.

直接来代码:

xmlns:s="library:///flex/spark"

xmlns:mx="library:///flex/mx"

minWidth="955" minHeight="600"

creationComplete="init();">

import flash.utils.setTimeout;

import mx.controls.Alert;

import mx.controls.sliderClasses.Slider;

import mx.events.SliderEvent;

[Embed(source="assets/videoIco/play_small.jpg")]

[Bindable]

private var playClass:Class;//播放图标样式

[Embed(source="assets/videoIco/pause.jpg")]

[Bindable]

private var pauseClass:Class;//暂停图标样式

[Embed(source="assets/videoIco/sound1.jpg")]

[Bindable]

private var sound:Class;//声音样式2(静音)

[Embed(source="assets/videoIco/sound2.jpg")]

[Bindable]

private var sound1:Class;//声音样式1

[Bindable]

private var _videoURL:String="rtmp://localhost:1935/live";//媒体路径

private var _videoName:String="1.flv";//播放视频名称

private var isPause:Boolean=false;//暂停状态

private var isSound:Boolean=true;//声音状态

private var isFullScreen:Boolean=false;//是否是全屏

[Bindable]

private var tmpSound:SoundTransform;//临时声音大小

[Bindable]

private var _playPosition:Number;//播放进度

private var _duration:Number;//定义播放时间

private var _nc:NetConnection;

private var _inNs:NetStream;

private var customClient:Object=new Object();

private var vi:Video;

private var flag:Boolean=false;//开始播放标志

private function init():void{

_nc=new NetConnection();//建立NetConnection对象

_nc.addEventListener(_STATUS,onNetStatusHandler);

_nc.client=this;

_nc.connect(_videoURL);

customClient.onMetaData=function(infoObject:Object):void{

vi.width=vdisplay.width;

vi.height=vdisplay.height;

vi.smoothing=true;

_duration=infoObject.duration;//获取视频持续时间

t_sh.maximum=_duration;//关联进度条最大值与视频总持续时间

th_sound.value=tmpSound.volume;

};

}

private function onNetStatusHandler(evt:NetStatusEvent):void{ switch(.code)

{

case"NetConnection.Connect.Success":

// Alert.show("连接RED5服务器成功!");

break;

case"NetStream.Play.Start":

trace("NetStream.Play.Start:");

break;

case"NetStream.Play.StreamNotFound":

trace("Unable to locate:"+_videoURL);

break;

default:

trace(.code);

}

}

public function onBWCheck(...arg):void{}

public function onBWDone(...arg):void{}

public function playButton():void{

//Alert.show(vdisplay.totalTime.toString());

if(!isPause){

if(!flag){

if(_nc==null){

init();

}

_inNs=new NetStream(_nc);

_inNs.addEventListener(_STATUS,onNetStatusHandler);

_inNs.client=customClient;

vi=new Video();

vi.attachNetStream(_inNs);

vdisplay.addChild(vi);

_inNs.play(_videoName);

flag=true;///已经开始播放标志

// Alert.show(tmpSound.volume.toString());

tmpSound=_inNs.soundTransform;

addEventListener(Event.ENTER_FRAME,onEnterFrame);

}

else

_inNs.resume();

playBtn.source=pauseClass;

isPause=true;

}

else

{

_inNs.pause();

playBtn.source=playClass;

isPause=false;

}

}

//时间格式操作

// private function formatTimes(value:int):String{

相关主题