如何调整视频大小

发布于 2024-11-27 19:05:42 字数 1729 浏览 1 评论 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);
}

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

谢谢!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-柠檬树下少年和吉他 2024-12-04 19:05:43

不要设置 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;
}

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;
}
下雨或天晴 2024-12-04 19:05:43

这有效,我必须更改 mediaContainer 尺寸为我当前的 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);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文