//创建一个 NetConnection 对象
002
var netConnection:NetConnection = new NetConnection();
003
/*如果连接到没有使用服务器的FLV 文件,则通过向 connect() 方法传递值
004
null,来播放流式 FLV 文件*/
005
netConnection.connect(null);
006
/*创建一个 NetStream 对象(该对象将 NetConnection 对象作为参数)并
007
指定要加载的 FLV 文件*/
008
var netStream:NetStream = new NetStream(netConnection);
009
netStream.play("test.flv");
010
/*使用 Video 类的 attachNetStream() 方法附加以前创建的 NetStream
011
对象(视频实例名为vid)*/
012
vid.attachNetStream(netStream);
013
//音量初始值
014
var yl:Number = 0.5;
015
var nsyl:SoundTransform = new SoundTransform();
016
//nsyl.volume=yl
017
018
//播放进度与加载进度影片缩放为0
019
bfjd_mc.scaleX = jzjd_mc.scaleX = 0;
020
//申明变量播放与下载百分比以及总时间(秒)的初始值为0
021
var bf_percent:int = 0;
022
var xz_percent:int = 0;
023
var _duration:Number = 0;
024
025
//指定在其上调用回调方法的对象
026
var _client:Object = new Object();
027
_client.onMetaData = onMetaData;
028
netStream.client = _client;
029
//按钮可见性与添加侦听事件
030
play_btn.visible = false;
031
pause_btn.visible = true;
032
pause_btn.addEventListener(MouseEvent.CLICK, zt);
033
play_btn.addEventListener(MouseEvent.CLICK, bf);
034
//忽略错误
035
netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
036
037
function asyncErrorHandler(event:AsyncErrorEvent):void {
038
}
039
040
//暂停
041
function zt(event:MouseEvent):void {
042
play_btn.visible = true;
043
pause_btn.visible = false;
044
//视频暂停
045
netStream.pause();
046
}
047
048
//播放
049
function bf(event:MouseEvent):void {
050
play_btn.visible = false;
051
pause_btn.visible = true;
052
//恢复回放暂停的视频流
053
netStream.resume();
054
addEventListener(Event.ENTER_FRAME, gx);
055
}
056
057
//接收在正播放的 FLV 文件中嵌入的描述性信息时调度
058
function onMetaData(data:Object):void {
059
_duration = data.duration;
060
}
061
//申明变量播放信号
062
var bfxh:String;
063
//侦听视频流的开始和末尾
064
netStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
065
066
function statusHandler(event:NetStatusEvent):void {
067
bfxh = event.info.code;
068
}
069
//不断更新进度与文本的显示
070
addEventListener(Event.ENTER_FRAME, gx);
071
072
function gx(event:Event):void {
073
if (netStream.bytesLoaded > 0){
074
//加载进度
075
xz_percent = netStream.bytesLoaded / netStream.bytesTotal * 100;
076
jzjd_mc.scaleX = xz_percent / 100;
077
}
078
079
if (_duration > 0 && netStream.time > 0){
080
//播放进度
081
bf_percent = netStream.time / _duration * 100;
082
bfjd_mc.scaleX = bf_percent / 100;
083
}
084
085
if (bfxh == "NetStream.Play.Stop"){
086
//播放完毕时的设置
087
bf_percent = 0;
088
bfjd_mc.scaleX = 0;
089
netStream.close();
090
//netStream.pause();
091
//netStream.seek(0); //将播放头置于视频开始处
092
play_btn.visible = true;
093
pause_btn.visible = false;
094
}
095
//文本显示内容
096
bftxt.text = Math.round(netStream.time / 60) + ":" + Math.round(netStream.time % 60);
097
zcdtxt.text = Math.round(_duration / 60) + ":" + Math.round(_duration % 60);
098
//音量控制
099
yl = (ylhk_mc.x - 345) / 50;
100
ylt_mc.scaleX = yl;
101
nsyl.volume = yl;
102
netStream.soundTransform = nsyl;
103
}
104
//音量滑块拖动控制
105
var fw:Rectangle = new Rectangle(345, 328, 50, 0); //拖动范围
106
ylhk_mc.addEventListener(MouseEvent.MOUSE_DOWN, ylhkax);
107
ylhk_mc.addEventListener(MouseEvent.MOUSE_UP, ylhksk);
108
stage.addEventListener(MouseEvent.MOUSE_UP, ylhksk);
109
110
function ylhkax(event:MouseEvent):void {
111
ylhk_mc.startDrag(false, fw);
112
}
113
114
function ylhksk(event:MouseEvent):void {
115
ylhk_mc.stopDrag();
116
}
002
var netConnection:NetConnection = new NetConnection();
003
/*如果连接到没有使用服务器的FLV 文件,则通过向 connect() 方法传递值
004
null,来播放流式 FLV 文件*/
005
netConnection.connect(null);
006
/*创建一个 NetStream 对象(该对象将 NetConnection 对象作为参数)并
007
指定要加载的 FLV 文件*/
008
var netStream:NetStream = new NetStream(netConnection);
009
netStream.play("test.flv");
010
/*使用 Video 类的 attachNetStream() 方法附加以前创建的 NetStream
011
对象(视频实例名为vid)*/
012
vid.attachNetStream(netStream);
013
//音量初始值
014
var yl:Number = 0.5;
015
var nsyl:SoundTransform = new SoundTransform();
016
//nsyl.volume=yl
017
018
//播放进度与加载进度影片缩放为0
019
bfjd_mc.scaleX = jzjd_mc.scaleX = 0;
020
//申明变量播放与下载百分比以及总时间(秒)的初始值为0
021
var bf_percent:int = 0;
022
var xz_percent:int = 0;
023
var _duration:Number = 0;
024
025
//指定在其上调用回调方法的对象
026
var _client:Object = new Object();
027
_client.onMetaData = onMetaData;
028
netStream.client = _client;
029
//按钮可见性与添加侦听事件
030
play_btn.visible = false;
031
pause_btn.visible = true;
032
pause_btn.addEventListener(MouseEvent.CLICK, zt);
033
play_btn.addEventListener(MouseEvent.CLICK, bf);
034
//忽略错误
035
netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
036
037
function asyncErrorHandler(event:AsyncErrorEvent):void {
038
}
039
040
//暂停
041
function zt(event:MouseEvent):void {
042
play_btn.visible = true;
043
pause_btn.visible = false;
044
//视频暂停
045
netStream.pause();
046
}
047
048
//播放
049
function bf(event:MouseEvent):void {
050
play_btn.visible = false;
051
pause_btn.visible = true;
052
//恢复回放暂停的视频流
053
netStream.resume();
054
addEventListener(Event.ENTER_FRAME, gx);
055
}
056
057
//接收在正播放的 FLV 文件中嵌入的描述性信息时调度
058
function onMetaData(data:Object):void {
059
_duration = data.duration;
060
}
061
//申明变量播放信号
062
var bfxh:String;
063
//侦听视频流的开始和末尾
064
netStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
065
066
function statusHandler(event:NetStatusEvent):void {
067
bfxh = event.info.code;
068
}
069
//不断更新进度与文本的显示
070
addEventListener(Event.ENTER_FRAME, gx);
071
072
function gx(event:Event):void {
073
if (netStream.bytesLoaded > 0){
074
//加载进度
075
xz_percent = netStream.bytesLoaded / netStream.bytesTotal * 100;
076
jzjd_mc.scaleX = xz_percent / 100;
077
}
078
079
if (_duration > 0 && netStream.time > 0){
080
//播放进度
081
bf_percent = netStream.time / _duration * 100;
082
bfjd_mc.scaleX = bf_percent / 100;
083
}
084
085
if (bfxh == "NetStream.Play.Stop"){
086
//播放完毕时的设置
087
bf_percent = 0;
088
bfjd_mc.scaleX = 0;
089
netStream.close();
090
//netStream.pause();
091
//netStream.seek(0); //将播放头置于视频开始处
092
play_btn.visible = true;
093
pause_btn.visible = false;
094
}
095
//文本显示内容
096
bftxt.text = Math.round(netStream.time / 60) + ":" + Math.round(netStream.time % 60);
097
zcdtxt.text = Math.round(_duration / 60) + ":" + Math.round(_duration % 60);
098
//音量控制
099
yl = (ylhk_mc.x - 345) / 50;
100
ylt_mc.scaleX = yl;
101
nsyl.volume = yl;
102
netStream.soundTransform = nsyl;
103
}
104
//音量滑块拖动控制
105
var fw:Rectangle = new Rectangle(345, 328, 50, 0); //拖动范围
106
ylhk_mc.addEventListener(MouseEvent.MOUSE_DOWN, ylhkax);
107
ylhk_mc.addEventListener(MouseEvent.MOUSE_UP, ylhksk);
108
stage.addEventListener(MouseEvent.MOUSE_UP, ylhksk);
109
110
function ylhkax(event:MouseEvent):void {
111
ylhk_mc.startDrag(false, fw);
112
}
113
114
function ylhksk(event:MouseEvent):void {
115
ylhk_mc.stopDrag();
116
}