·您当前的位置:首页 > 技术教程 > FMS教程 >

[FMS]FMS音频质量的稍微提高

时间:2014-12-01 16:17酷播
[FMS]FMS 音频质量的稍微提高,fms音频,fms配置

直接贴出部分源码:

  1. package  
  2. { 
  3.     import flash.display.Sprite; 
  4.     import flash.events.NetStatusEvent; 
  5.     import flash.net.NetConnection; 
  6.     import flash.net.NetStream; 
  7.     import flash.media.Microphone; 
  8.     import flash.media.SoundCodec; 
  9.  
  10.     public class Main extends Sprite 
  11.     { 
  12.         private var nc:NetConnection; 
  13.         private var nsAudio:NetStream; 
  14.         private var nsVideo:NetStream; 
  15.         private var nsPlayVideo:NetStream; 
  16.         private var nsPlayAudio:NetStream; 
  17.  
  18.         public function Main():void 
  19.         { 
  20.             nc=new NetConnection(); 
  21.             nc.client = this; 
  22.             nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); 
  23.             nc.connect("rtmp://localhost/TestAudioMore","我心空"); 
  24.         } 
  25.  
  26.         private function netStatusHandler(e:NetStatusEvent) 
  27.         { 
  28.             var code:String = e.info.code; 
  29.             switch (code) 
  30.             { 
  31.                 case "NetConnection.Connect.Success" : 
  32.                     publishAudio(0); 
  33.                     break; 
  34.                 default : 
  35.                     break; 
  36.             } 
  37.         } 
  38.  
  39.         //分别发布音频,视频 
  40.         private function publishAudio(id) 
  41.         { 
  42.             if (nsAudio==null) 
  43.             { 
  44.                 nsAudio = new NetStream(nc); 
  45.                 nsAudio.client = this; 
  46.                 nsAudio.bufferTime = 2; 
  47.                 var mic:Microphone = Microphone.getMicrophone(); 
  48.                 if (mic!=null) 
  49.                 { 
  50.                     mic.codec = SoundCodec.SPEEX; 
  51.                     mic.encodeQuality = 4; 
  52.                     mic.noiseSuppressionLevel = 0; 
  53.                     mic.setSilenceLevel(10,1000); 
  54.                     mic.setUseEchoSuppression(true); 
  55.                     mic.setLoopBack(false); 
  56.                     mic.gain = 50; 
  57.                     nsAudio.attachAudio(mic); 
  58.                 } 
  59.                 nsAudio.publish("audio"+id,"live"); 
  60.             } 
  61.         } 
  62.  
  63.         private function publishVideo(id) 
  64.         { 
  65.             if (nsVideo==null) 
  66.             { 
  67.                 nsVideo=new NetStream(); 
  68.                 nsVideo.client = this; 
  69.                 nsVideo.bufferTime = 2; 
  70.                 var cam:Camera = Camera.getCamera(); 
  71.                 if (cam!=null) 
  72.                 { 
  73.                     cam.setQuality(0,80); 
  74.                     cam.setMode(160,130,7); 
  75.                     nsVideo.attachCamera(cam); 
  76.                 } 
  77.                 nsVideo.publish("video"+id,"live"); 
  78.             } 
  79.         } 
  80.          
  81.         //分别播放视频音频 
  82.          
  83.         private function playVideo(id) 
  84.         { 
  85.             clearVideoStream(); 
  86.             nsPlayVideo=new NetStream(nc); 
  87.             var vid:Video=new Video(); 
  88.             vid.attachNetStream(nsPlayVideo); 
  89.             vid.width=240; 
  90.             vid.height=150; 
  91.             addChild(vid); 
  92.             nsPlayVideo.play("video"+id); 
  93.         } 
  94.  
  95.         /** 
  96.         *清除视频 
  97.         */ 
  98.         private function clearVideoStream(clearPublish:Boolean=false) 
  99.         { 
  100.             if (nsPlayVideo) 
  101.             { 
  102.                 nsPlayVideo.close(); 
  103.                 nsPlayVideo = null; 
  104.             } 
  105.  
  106.             if (nsVideo&&clearPublish) 
  107.             { 
  108.                 nsVideo.close(); 
  109.                 nsVideo = null; 
  110.             } 
  111.         } 
  112.  
  113.         /** 
  114.         *清除音频 
  115.         */ 
  116.         private function clearAudioStream(clearPublish:Boolean=false) 
  117.         { 
  118.             if (nsPlayAudio) 
  119.             { 
  120.                 nsPlayAudio.close(); 
  121.                 nsPlayAudio = null; 
  122.             } 
  123.  
  124.             if (nsAudio&&clearPublish) 
  125.             { 
  126.                 nsAudio.close(); 
  127.                 nsAudio = null; 
  128.             } 
  129.         } 
  130.  
  131.         public function Welcome(str) 
  132.         { 
  133.             trace(str,",欢迎你的到来。义无反顾,彻底的放下心扉"); 
  134.         } 
  135.  
  136.     } 
  137. } 

通讯文件main.asc

  1.  application.onConnect=function(newClient,aname) 
  2.  { 
  3.      application.acceptConnection(newClient); 
  4.      
  5.      newClient.call("Welcome",null,aname); 
  6. } 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器