隨筆-193  評論-715  文章-1  trackbacks-0
          Recently, I had spent a lot of time on sound playback of Flash Player 10, but I can't slove a performance issue in none-ActiveX architecture. I will get stutter/machine gun sound when I load a heavy load web page at the same time in Firefox/Chrome/Safari. this case don't happen in IE, and I always get smooth sound.

          The root cause of this issue is used to extract method of Sound class for retract samples, and then play by extracted samples. You may ask me, why don't use play method of Sound class directly? I think I only answer you that it's business requirements.

          Following are my test code:
          package {
              
          import flash.events.Event;
              
          import flash.events.SampleDataEvent;
              
          import flash.media.Sound;
              
          import flash.net.URLRequest;
              
          import flash.system.System;
              
          import flash.utils.ByteArray;

              
          public class Extract {
                  
          private var sourceSnd:Sound = new Sound();
                  
          private var outputSnd:Sound = new Sound();
                  
          private var urlReq:URLRequest = new URLRequest("11k.mp3"); //this file has 575 frames
                  
          //        private var urlReq:URLRequest = new URLRequest("44k.mp3");  //this file has 1150 frames
                  private var samplesCount:uint = 0;

                  
          public function play():void {
                      sourceSnd.load(urlReq);
                      
          //            sourceSnd.play(); // if use source sound to playing, we will not be got machine gun sound.
                      sourceSnd.addEventListener(Event.COMPLETE, loaded); //use this approach, we will be got stutter.
                  }


                  
          private function loaded(event:Event):void {
                      outputSnd.addEventListener(SampleDataEvent.SAMPLE_DATA, processSound);
                      outputSnd.play();
                  }


                  
          private function processSound(event:SampleDataEvent):void {
                      var bytes:ByteArray 
          = new ByteArray();
                      var samplesPerTime:uint 
          = sourceSnd.extract(bytes, 8192);
                      samplesCount 
          += samplesPerTime;
                      
          //            trace("samplesCount:" + samplesCount + ",samplesPerTime:" + samplesPerTime);
                      event.data.writeBytes(bytes);
                      
          //            flash.system.System.gc();
                  }


              }

          }

          You can refer to following test steps for reproduce stutter/machine gun sound issue:
           
          1, Run/debug test application in Firefox, you will get smooth sound at once.
           
          2, Open a new tab in the same window, and open a heavy load web page (for example: http://www.taobao.com)
           
          3, You will get stutter when a heavy load page is loading.

          If you interest in this problem also, we can study it together.
          posted on 2010-03-05 12:15 Robin's Programming World 閱讀(1579) 評論(0)  編輯  收藏 所屬分類: Flex & Flash
          <2010年3月>
          28123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(49)

          隨筆分類(215)

          隨筆檔案(181)

          相冊

          收藏夾

          Friend Links

          • Tiger的Blog,專注于過程改進,項目管理,質量管理三個方向。
          • zrfunds

          搜索

          •  

          積分與排名

          • 積分 - 755495
          • 排名 - 60

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 泸溪县| 中江县| 涟水县| 社会| 平利县| 饶平县| 刚察县| 莱芜市| 宁德市| 扎兰屯市| 府谷县| 喀喇| 穆棱市| 东莞市| 绿春县| 琼海市| 东兴市| 柳河县| 土默特右旗| 综艺| 怀来县| 曲松县| 阿坝县| 塔城市| 航空| 云安县| 武川县| 吉隆县| 莱西市| 崇仁县| 内丘县| 云安县| 依安县| 平果县| 万荣县| 辰溪县| 石家庄市| 芜湖县| 雷州市| 蕉岭县| 汉川市|