我正在构建一个具有两个可切换大小的播放器,由用户更改,但我没有结果。
那是我的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 :(得分:2)
而不是设置VideoElement的width和height属性,将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;
}
答案 1 :(得分:0)
这很有用,我不得不更改mediaContainer维度和为我当前的videoElement定义一个新的layoutMetadata:
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);
}