flex NetStream动态加载视频利用SoundTransform控制音量


<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
viewSourceURL="srcview/index.html" xmlns:local="*"
initialize="init();">

<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var urlArr:Array=["http://221.122.36.143/oa/video/1.flv", "http://221.122.36.143/oa/video/2.flv", "http://221.122.36.143/oa/video/p2.mp4"];
public function init():void{
myVideo.urlArr = urlArr;
myVideo.total = 100000;
// Alert.show("1==>>"+myVideo.urlArr.length);
}

]]>
</mx:Script>

<local:mVideo id="myVideo"/>

</mx:Application>

第二个文件
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="setTransformVolume();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.SliderEvent;

private var nc:NetConnection;
private var ns:NetStream;
private var nc2:NetConnection;
private var ns2:NetStream;
private var video:Video;

[Bindable]
public var urlArr:Array=null;
[Bindable]
public var total:Number=0;

private var count:int=0;
private var finished1:int=1; //1:播放正在进行;0:播放结束
private var finished2:int=0; //1:播放正在进行;0:播放结束

private var volumeTransform:SoundTransform;


private function setTransformVolume():void{
volumeTransform=new SoundTransform();
slider.value = volumeTransform.volume;
slider.tickInterval = slider.snapInterval;
slider.liveDragging = true;
slider.addEventListener(Event.CHANGE, volumeChangeHandler);
init();
}

private function init():void
{
Alert.show("" + total);

var nsClient:Object={};
nc=new NetConnection();
nc.connect(null);
ns=new NetStream(nc);
ns.play(urlArr[count]);
ns.client=nsClient;
ns.soundTransform=volumeTransform;
ns.addEventListener(NetStatusEvent.NET_STATUS, myTest1);

video=new Video();
video.name="video1";
video.width=uic.width;
video.height=uic.height;
video.attachNetStream(ns);
if (uic.getChildByName("video1") != null)
{
uic.removeChild(uic.getChildByName("video1"));
}

count++;
}
private function volumeChangeHandler(event:SliderEvent):void {
volumeTransform.volume = slider.value;
ns.soundTransform = volumeTransform;
ns2.soundTransform = volumeTransform;
}
private function init2():void
{

var nsClient:Object={};

nc2=new NetConnection();
nc2.connect(null);
ns2=new NetStream(nc2);
ns2.play(urlArr[count]);
ns2.client=nsClient;
ns2.soundTransform=volumeTransform;
ns2.addEventListener(NetStatusEvent.NET_STATUS, myTest2);

video=new Video();
video.name="video2";
video.width=uic.width;
video.height=uic.height;
video.attachNetStream(ns2);
if (uic.getChildByName("video2") != null)
{
uic.removeChild(uic.getChildByName("video2"));
}
count++;
}

private function myTest1(event:NetStatusEvent):void
{
trace("count1==>>" + count);
trace("count1 onStatus:" + event.info.code);
if (event.info.code == "NetStream.Buffer.Full")
{
if (count == 1)
{
uic.addChild(video);
init2();
}
if (finished2 == 1)
{
ns.seek(0);
ns.pause();
}
}
else if (event.info.code == "NetStream.Play.Stop")
{
finished1=0;
finished2=1;
uic.addChild(video);
ns2.togglePause();
if (count <= urlArr.length)
{
init();
}

}

}

private function myTest2(event:NetStatusEvent):void
{
trace("count2==>>" + count);
trace("count2 onStatus:" + event.info.code);
if (event.info.code == "NetStream.Buffer.Full")
{
if (finished1 == 1)
{
ns2.seek(0);
ns2.pause();
}
}
else if (event.info.code == "NetStream.Play.Stop")
{
finished2=0;
finished1=1;
uic.addChild(video);
ns.togglePause();
if (count <= urlArr.length)
{
init2();
}
}

}

public function stopVideo():void
{
uic.stop();
}
]]>
</mx:Script>
<mx:VideoDisplay id="uic"
width="550"
height="450"
volume="{slider.value}"/>

<mx:ControlBar>
<mx:HSlider id="slider"
minimum="0.0"
maximum="1.0"
snapInterval="0.1"
tickInterval="0.1"
liveDragging="true"/>
<mx:Button label="Play/Pause"
click="uic.play();"/>
<mx:Button label="Rewind"
click="stopVideo();"/>
</mx:ControlBar>
</mx:Panel>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值