How to resize a video
I'm building a player with two switchable sizes, changed by the user, but I'm not having results on that.
That's my setupPlayer function, which works fine:
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 //
}
Then, I feed the player and it starts to play normally, it's when I try 开发者_StackOverflow中文版to resize it. (I did read somewhere that I needed to change the LayoutMetadata), but have no effect:
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);
}
Someone can point where my error is?
Thanks!
instead of setting width and height properties of the VideoElement, set the MediaContainer's width and height to _playerWidth and _playerHeight respectively. Try the code below and see if it solves you problem
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;
}
This worked, I had to change mediaContainer dimensions and define a new layoutMetadata for my current 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);
}
精彩评论