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);
}

有人可以指出我的错误在哪里?

谢谢!

4

2 回答 2

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;
}
于 2011-08-05T12:53:32.480 回答
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);
}
于 2011-08-05T21:16:34.793 回答