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

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

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

直接贴出部分源码:

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

通讯文件main.asc

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

 

热门文章推荐

请稍候...

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

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