flex4+fms3.5+cs4开发实时音视频直播及点播详解[组图](2)
flex部分 ? xml version = 1.0 encoding = utf-8 ? s:WindowedApplication xmlns:fx = http://ns.adobe.com/mxml/2009 xmlns:s = library://ns.adobe.com/flex/spark xmlns:mx = library://ns.adobe.com/flex/mx wi
flex部分
- <?xml version="1.0" encoding="utf-8"?>
- <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx" width="430" height="340"
- creationComplete="init_creationCompleteHandler(event)"
- closing="unonload()">
- <s:layout>
- <s:BasicLayout/>
- </s:layout>
- <fx:Style source="media.css"/>
- <fx:Script>
- <!--[CDATA[
- import flash.events.NetStatusEvent;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import mx.collections.ArrayCollection;
- import mx.controls.Alert;
- import mx.controls.Text;
- import mx.events.FlexEvent;
- private var nc:NetConnection;
- private var ns:NetStream;
- private var vi:Video;
- private var cam:Camera;
- private var microphone:Microphone;
- private var fmsArr:ArrayCollection=new ArrayCollection([]);
- private var sharedObject:SharedObject=SharedObject.getLocal("com.ue");
- /**
- * 初始化
- */
- protected function init_creationCompleteHandler(event:FlexEvent):void{
- var loader:URLLoader = new URLLoader();
- loader.dataFormat=URLLoaderDataFormat.VARIABLES;
- loader.addEventListener(Event.COMPLETE, loader_complete);
- loader.load(new URLRequest("global.txt"));
- function loader_complete(e:Event):void {
- var variables:URLVariables=new URLVariables(loader.data);
- trace(variables["servers"]);
- var serversArr:Array = variables["servers"].toString().split("@#@");
- for(var i:int=0;i<serversArr.length;i++){
- var server:String = serversArr[i];
- var sArr:Array = server.toString().split("$#$");
- fmsArr.addItem({label:sArr[0], value:sArr[1]});
- }
- }
- getCookie();
- }
- public function getCookie():void{
- if(sharedObject.data["pmhidh"]!=null){
- pmhID.text = sharedObject.data["pmhidh"];
- }
- if(sharedObject.data["spfwq"]!=null){
- trace(sharedObject.data["spfwq"]);
- fms.selectedItem = sharedObject.data["spfwq"];
- }
- if(sharedObject.data["yl"]!=null){
- slider.value = sharedObject.data["yl"];
- }
- }
- /**
- * 开始直播
- */
- protected function startButton_clickHandler(event:MouseEvent):void{
- startButton.enabled=false;
- stopButton.enabled=true;
- nc = new NetConnection();
- nc.addEventListener(NetStatusEvent.NET_STATUS,connectServerHander);
- nc.client = this;
- trace(fms.selectedItem.label);
- nc.connect(fms.selectedItem.value);
- slider.enabled=true;
- }
- /**
- * 回调函数
- */
- public function connectServerHander(evt:NetStatusEvent):void{
- cam = Camera.getCamera();
- microphone = Microphone.getMicrophone();
- if(microphone!=null){
- microphone.setSilenceLevel(0);//总是收集音频
- microphone.rate=44;
- }else{
- Alert.show("无法链接到麦克风!");
- }
- if(cam != null){
- cam.setMode(176,144,25);
- cam.setQuality(0,90);
- ns = new NetStream(nc);
- ns.attachCamera(cam);
- ns.attachAudio(microphone);
- ns.publish(pmhID.text,"append");
- vi = new Video();
- vi.width = player.width;
- vi.height = player.height;
- vi.attachCamera(cam);
- player.addChild(vi);
- }else{
- Alert.show("无法链接到摄像头!");
- }
- }
- /**
- * NetConnection回调函数
- */
- public function onBWDone():void{}
- /**
- * 保存音视频文件
- */
- // protected function browse_clickHandler(event:MouseEvent):void{
- // var file:File = new File();
- // file.addEventListener(Event.SELECT,dirSelected);
- // file.browseForSave("另存为");
- // function dirSelected(e:Event):void {
- // trace(file.nativePath);
- // filefilePath.text = file.nativePath;
- // }
- // }
- /**
- * 音量控制
- */
- protected function slider_changeHandler(event:Event):void{
- microphone.gain = slider.value;
- }
- /**
- * 停止发布
- */
- protected function stopButton_clickHandler(event:MouseEvent):void{
- ns.close();
- vi.visible=false;
- startButton.enabled=true;
- stopButton.enabled=false;
- }
- /**
- * 关闭窗口触发事件,保存配置
- */
- public function unonload():void{
- if(sharedObject!=null){
- sharedObject.clear();
- }
- if(sharedObject.data["pmhidh"]==null){
- sharedObject.data["pmhidh"] = pmhID.text;
- }
- if(sharedObject.data["spfwq"]==null){
- sharedObject.data["spfwq"] = fms.selectedItem;
- }
- if(sharedObject.data["yl"]==null){
- sharedObject.data["yl"] = slider.value;
- }
- sharedObject.flush();
- }
- ]]-->
- </fx:Script>
- <fx:Declarations>
- <!-- 将非可视元素(例如服务、值对象)放在此处 -->
- </fx:Declarations>
- <s:Panel width="100%" height="100%" x="0" y="0" id="panel1">
- <s:layout>
- <s:VerticalLayout paddingLeft="0" paddingRight="0" paddingBottom="0" paddingTop="0" requestedRowCount="7"/>
- </s:layout>
- <s:VGroup width="430" height="272" paddingTop="10" paddingBottom="0" paddingRight="0" paddingLeft="0">
- <s:HGroup width="430" height="220" paddingLeft="5" paddingTop="2" paddingBottom="0" paddingRight="5">
- <s:BorderContainer width="206" height="215">
- <s:VideoDisplay width="193" height="202" scaleMode="letterbox" id="player" x="5" y="5"/>
- </s:BorderContainer>
- <s:BorderContainer width="206" height="215">
- <s:VGroup width="193" height="208" paddingLeft="5" paddingTop="0" paddingBottom="0"
- paddingRight="5" gap="9" x="5" y="5">
- <s:Label text="拍卖会ID号:" height="14" id="pmhIDLabel"/>
- <s:TextInput id="pmhID"/>
- <s:Label text="视频服务器:" height="14"/>
- <s:ComboBox id="fms" dataProvider="{fmsArr}"/>
- <s:Label text="音量" height="14"/>
- <s:HSlider id="slider" enabled="false" change="slider_changeHandler(event)" minimum="0"
- maximum="100" stepSize="10"/>
- </s:VGroup>
- </s:BorderContainer>
- </s:HGroup>
- <s:HGroup width="430" height="35" paddingTop="0" paddingBottom="0" paddingRight="5" paddingLeft="145"
- verticalAlign="middle" textAlign="center">
- <s:Button id="startButton" label="开始发布" click="startButton_clickHandler(event)"/>
- <s:Button label="停止发布" id="stopButton" enabled="false" click="stopButton_clickHandler(event)"/>
- </s:HGroup>
- </s:VGroup>
- </s:Panel>
- </s:WindowedApplication>
效果如下:
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...