2011-08-05 134 views
0

我正在構建一個有兩種可切換大小的播放器,由用戶更改,但我沒有獲得相關結果。如何調整視頻的大小

這是我的setupPlayer功能,工作正常:

function setupPlayer():void 
{ 

      layout.width = _playerWidth; 
      layout.height = _playerHeight; 
      layout.layoutMode = LayoutMode.HORIZONTAL 
      layout.horizontalAlign = HorizontalAlign.CENTER; 
      layout.verticalAlign = VerticalAlign.TOP; 
      layout.scaleMode = ScaleMode.LETTERBOX; 

      videoElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout); 
      videoElement.smoothing = true; 

      mediaPlayer.loop = false; 
      mediaPlayer.autoPlay = _autoPlay;    
      mediaContainer.addMediaElement(videoElement); 
      videoCanvas.addChild(mediaContainer);  

       .... // more code // 
} 

然後,我喂的球員,它開始正常播放,這是當我試圖調整其大小。 (我沒地方讀書,我需要改變LayoutMetadata),但沒有任何效果:

public function resize(width:Number, height:Number):void 
{ 
      // none of this worked 
      //mediaContainer.width = 1200; 
      //mediaContainer.height = 2000; 
      //mediaContainer.layout(1200, 2000, true); 


      // neither this 
      var layout:LayoutMetadata = new LayoutMetadata(); 
      layout.width = 1500; 
      layout.height = 1500; 
      layout.layoutMode = LayoutMode.HORIZONTAL 
      layout.horizontalAlign = HorizontalAlign.CENTER; 
      layout.verticalAlign = VerticalAlign.TOP; 
      layout.scaleMode = ScaleMode.STRETCH; 

      videoElement.removeMetadata(LayoutMetadata.LAYOUT_NAMESPACE) 
      videoElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout); 
} 

有人能在我的錯誤是什麼?

謝謝!

回答

0

這個工作,我不得不改變mediaContainer尺寸定義一個新的layoutMetadata我目前videoElement:

public function resize(width:Number, height:Number):void 
{ 
      mediaContainer.width = width; 
      mediaContainer.height = height; 

      var layout:LayoutMetadata = new LayoutMetadata(); 
      layout.width = width; 
      layout.height = height; 
      layout.layoutMode = LayoutMode.HORIZONTAL; 
      layout.horizontalAlign = HorizontalAlign.CENTER; 
      layout.verticalAlign = VerticalAlign.TOP; 
      layout.scaleMode = ScaleMode.STRETCH; 

      videoElement.removeMetadata(LayoutMetadata.LAYOUT_NAMESPACE); 
      videoElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout); 
} 
2

而不是設置VideoElement的寬度和高度屬性,分別將MediaContainer的寬度和高度設置爲_playerWidth和_playerHeight。嘗試下面的代碼,看看它是否解決你的問題

function setupPlayer():void 
{ 

      mediaContainer.width = _playerWidth; 
      mediaContainer.height = _playerHeight; 

      layout.layoutMetadata.percentWidth = 100; 
      layout.layoutMetadata.percentHeight = 100; 
      layout.scaleMode = ScaleMode.LETTERBOX; 

      videoElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout); 
      videoElement.smoothing = true; 

      mediaPlayer.loop = false; 
      mediaPlayer.autoPlay = _autoPlay;    
      mediaContainer.addMediaElement(videoElement); 
      videoCanvas.addChild(mediaContainer);  

       .... // more code // 
} 

public function resize(width:Number, height:Number):void 
{ 
      // none of this worked 
      mediaContainer.width = 1200; 
      mediaContainer.height = 2000; 
} 
+0

我想出如何做到這一點,我需要改變mediaContainer **和**設置一個新的layouMetadata。 –