如何调整视频大小
我正在构建一个具有两种可切换尺寸的播放器,由用户更改,但我没有得到结果。
这是我的 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);
}
有人可以指出我的错误在哪里?
谢谢!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要设置 VideoElement 的宽度和高度属性,而是将 MediaContainer 的宽度和高度分别设置为 _playerWidth 和 _playerHeight。尝试下面的代码,看看是否能解决您的问题
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
这有效,我必须更改 mediaContainer 尺寸并为我当前的 videoElement 定义一个新的布局元数据:
This worked, I had to change mediaContainer dimensions and define a new layoutMetadata for my current videoElement: