2011-11-23 126 views
0

我有下面的代碼來播放存儲在媒體服務器的視頻:調整大小的視頻孩子同樣大小

<?xml version="1.0" encoding="utf-8"?> 
<s:Group 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="592" height="372"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 
      import mx.events.ResizeEvent; 

      private var ns:NetStream; 
      private var nc:NetConnection; 
      private var video:Video; 
      private var meta:Object; 

      private function ns_onMetaData(item:Object):void { 
       trace("meta"); 
       meta = item; 
       // Resize Video object to same size as meta data. 
       video.width = item.width; 
       video.height = item.height; 
       // Resize UIComponent to same size as Video object. 
       myVid.width = video.width; 
       myVid.height = video.height; 

      } 

      private function fetch_rec():void { 
       var nsClient:Object = {}; 
       nsClient.onMetaData = ns_onMetaData; 


       nc = new NetConnection(); 
       nc.connect(null); 
       ns = new NetStream(nc); 
       ns.client = nsClient; 

       video = new Video(); 
       video.attachNetStream(ns); 
       video.smoothing=true; 
       myVid.addChild(video); 
       ns.play("http://localhost:5080/oflaDemo/recordings/firstattempt.flv"); 

      } 



     ]]> 
    </fx:Script> 

    <mx:VideoDisplay id="myVid" bottom="0" width="100%" height="100%"     
    /*??how to make the progressbar work???*/    playheadUpdate="progBar.setProgress(myVid.playheadTime,myVid.totalTime)"/> 

    <s:HGroup right="10" top="7"> 
     <mx:Button id="button4" x="498" y="250" label="Play/Reload" click="fetch_rec();"/> 
     <mx:Button id="button5" x="512" y="279" label="Pause" click="ns.pause()"/> 
    </s:HGroup> 

    <mx:ProgressBar id="progBar" left="10" right="10" bottom="7" height="10" label="" mode="manual"/> 


</s:Group> 

,我想知道 1)如何使視頻跟隨調整myVid VideoDisplay的大小,並不像它那樣顯示小內容,並且 2)如何使進度條適用於流式視頻...

在此先感謝您的幫助!

回答

1

我無法回答進度條。爲了縮放視頻到視頻顯示器,我使用Transform和Matrix,當VideoDisplay大小發生變化時,我只需用新的縮放比例替換舊的Matrix。如果你的視頻會更小,那麼目標應該擴大。

這裏是代碼段(我跳過創造等):

<!-- language: lang-xml --> 

protected function scaleVideoToDisplay():void { 
    var ratio:Number; 
    if (video == null) { 
     return; 
    }else if (video.width == 0 || video.height == 0) { 
     ratio = 0.0; 
    }else { 
     ratio = Math.min(
       videoDisplay.width/video.width, 
       videoDisplay.height/video.height); 
    } 
    video.transform.matrix = new Matrix(ratio, 0, 0, ratio); 
} 
<s:VideoDisplay width="100%" height="100%" resize="scaleVideoToDisplay()"/> 
<!-- langugae:lang-none --> 

用於製作視頻我用:

<!-- language: lang-xml --> 

video.transform = new Transform(video); 

除了這個你可能會擴展創建後視頻。