调整 flash.media.Video 的大小

发布于 2024-09-04 05:37:55 字数 2200 浏览 2 评论 0原文

我无法调整包装 flash.media.Video 对象的自定义 UIComponent 大小(我选择这种方式的原因是因为 mx.control.VideoDisplay< /code> 不支持 flash.media.Video 中提供的流播放,即 attachNetStream())。一旦我创建了 320x240 Video 尺寸并将其从其父级中删除,我就无法将其替换为另一个更大或更小的尺寸。

这是我的代码(这个代码只捕获Camera而不是NetStream)。

package media
{
    import flash.media.Camera;
    import flash.media.Video;

    import mx.controls.VideoDisplay;
    import mx.core.UIComponent;

    public class VideoUI extends UIComponent
    {
        private var video:Video;

        public function VideoUI(width:int, height:int)
        {
            super();
            video = new Video(width, height);
            var cam:Camera = Camera.getCamera();
            video.attachCamera(cam);
            addChild(video);
        }
    }
}

另一部分,

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import media.VideoUI;

            private function addVideoOutput():void
            {
                // initial video size
                var video:VideoUI = new VideoUI(160,120);
                HBoxVideo.addChild(video);              
            }

            protected function resizeVideo(event:MouseEvent):void
            {
                var videoList:Array = HBoxVideo.getChildren();
                for (var i:int = 0; i < videoList.length; i++)
                {
                    var video:VideoUI = videoList.pop();
                    HBoxVideo.removeChild(video);
                    // new size that produce the previous size :(
                    video = new VideoUI(320, 240);
                    HBoxVideo.addChild(video);
                }
            }

        ]]>
    </mx:Script>
    <mx:Button click="addVideoOutput()" x="10" y="265" label="add"/>
    <mx:HBox x="10" y="10" width="100%" id="HBoxVideo">
    </mx:HBox>
    <mx:Button x="58" y="265" label="resize" click="resizeVideo(event)" id="resizeButton"/>
</mx:Application>

非常感谢。

I'm having trouble to resize my custom UIComponent that wrap flash.media.Video object (The reason I choose this way is because mx.control.VideoDisplay doesn't support streaming playback that available in flash.media.Video that is attachNetStream()). Once I create a 320x240 Video size and remove it from its parent, I can't replace it with another one, bigger or smaller.

Here's my code (this one only capture Camera not NetStream).

package media
{
    import flash.media.Camera;
    import flash.media.Video;

    import mx.controls.VideoDisplay;
    import mx.core.UIComponent;

    public class VideoUI extends UIComponent
    {
        private var video:Video;

        public function VideoUI(width:int, height:int)
        {
            super();
            video = new Video(width, height);
            var cam:Camera = Camera.getCamera();
            video.attachCamera(cam);
            addChild(video);
        }
    }
}

The other part,

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import media.VideoUI;

            private function addVideoOutput():void
            {
                // initial video size
                var video:VideoUI = new VideoUI(160,120);
                HBoxVideo.addChild(video);              
            }

            protected function resizeVideo(event:MouseEvent):void
            {
                var videoList:Array = HBoxVideo.getChildren();
                for (var i:int = 0; i < videoList.length; i++)
                {
                    var video:VideoUI = videoList.pop();
                    HBoxVideo.removeChild(video);
                    // new size that produce the previous size :(
                    video = new VideoUI(320, 240);
                    HBoxVideo.addChild(video);
                }
            }

        ]]>
    </mx:Script>
    <mx:Button click="addVideoOutput()" x="10" y="265" label="add"/>
    <mx:HBox x="10" y="10" width="100%" id="HBoxVideo">
    </mx:HBox>
    <mx:Button x="58" y="265" label="resize" click="resizeVideo(event)" id="resizeButton"/>
</mx:Application>

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

讽刺将军 2024-09-11 05:37:55

默认情况下,Video 类的新实例的宽度为 320 像素,高度为 240 像素。您需要访问 VideoUI 类中的视频,以便更改宽度高度

如下所示:

将 VideoUI.as 中 video 变量的所有外观更改为

_video

并应用 getter。

新视频 UI 类

package media
{
    import flash.media.Camera;
    import flash.media.Video;

    import mx.core.UIComponent;

    public class VideoUI extends UIComponent
    {
        private var _video:Video;

        public function VideoUI(width:int, height:int)
        {
            super();
            _video = new Video(width, height);
            var cam:Camera = Camera.getCamera();
            _video.attachCamera(cam);
            addChild(_video);
        }

        public function get video():Video{
            return _video;
        }
    }
}

主 mxml 文件替换

video = new VideoUI(320, 240);

video.video.width=320;
video.video.height=240;

注意:您应该将 VideoUI 实例重命名为 videoui 或各种各样的。这有点令人困惑。您还可以将其移至 VideoUI 类或创建一个方法。选择权在你。

By default, new instances of the Video class are 320 pixels wide by 240 pixels high. You will need access to your video in the VideoUI Class so that you can change the width and height.

As follows:

Change all appearances of your video variable in VideoUI.as to

_video

and apply a getter.

New Video UI Class

package media
{
    import flash.media.Camera;
    import flash.media.Video;

    import mx.core.UIComponent;

    public class VideoUI extends UIComponent
    {
        private var _video:Video;

        public function VideoUI(width:int, height:int)
        {
            super();
            _video = new Video(width, height);
            var cam:Camera = Camera.getCamera();
            _video.attachCamera(cam);
            addChild(_video);
        }

        public function get video():Video{
            return _video;
        }
    }
}

Replace in your main mxml file

video = new VideoUI(320, 240);

with

video.video.width=320;
video.video.height=240;

Note: You should rename your VideoUI instance to videoui or the sorts. It is a little confusing. You can also move this to your VideoUI Class or make a method. The choice is yours.

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