【问题标题】:Resize PopUp video maintaining the aspect ratio in flex调整弹出视频的大小,保持 flex 中的纵横比
【发布时间】:2011-12-12 14:05:37
【问题描述】:

我有一个 TitleWindow 弹出窗口,当我单击拇指时,它会打开一个 videoDisplay 来播放视频。我想要的是我的弹出窗口调整大小和其中的视频,但要保持其原始纵横比而不是拉伸...

有什么想法吗?

非常感谢!这是我的弹出窗口:

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx"
           close="CloseWindow(event)" >
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
        import mx.events.CloseEvent;
        import mx.events.ResizeEvent;
        import mx.managers.PopUpManager;


        [Bindable]public var mediaServerUrl:String;
        [Bindable]public var videoFolder:String;
        [Bindable]public var filename:String;
        [Bindable]public var comments:String;


        private var ns:NetStream;
        private var nc:NetConnection;
        private var video:Video;
        private var meta:Object;

        private function ns_onMetaData(item:Object):void {
            trace("meta");
            meta = item;
            // Resize Video object to same size as meta data.
            video.width = item.width;
            video.height = item.height;
            // Resize UIComponent to same size as Video object.
            myVid.width = video.width;
            myVid.height = video.height;

        }

        private function fetch_rec():void {
            var nsClient:Object = {};
            nsClient.onMetaData = ns_onMetaData;


            nc = new NetConnection();
            nc.connect(null);
            ns = new NetStream(nc);
            ns.client = nsClient;

            video = new Video(myVid.width,myVid.height);
            video.attachNetStream(ns);
            video.smoothing=true;
            myVid.addChild(video);
            ns.play(mediaServerUrl+"/"+videoFolder+"/"+filename+".flv");

        }

        protected function CloseWindow(event:CloseEvent):void
        {
            ns.close();
            nc.close();
            PopUpManager.removePopUp(this);

        }

    ]]>
</fx:Script>

<mx:VideoDisplay id="myVid" visible="true" x="0" bottom="50" width="100%" height="100%"
                 maintainAspectRatio="true"
                 autoPlay="true" 
                 creationComplete="fetch_rec()"
                 playheadUpdate="progBar.setProgress(myVid.playheadTime,myVid.totalTime)"/>

<mx:ProgressBar id="progBar" left="10" right="10" bottom="60" height="10" label="" mode="manual"/>
<s:Label x="10" bottom="30" text="Σχόλια:"/>

<s:Label x="10" bottom="10" text="{comments}"/></s:TitleWindow>

调用这个弹出窗口:

 protected function launchPopUp(event:MouseEvent):void
        {
            if(list.selectedItem){
                win = new ViewVideoPopUp();
                win.width = this.width;
                win.height = this.height;

                //give what is needed to play the video selected
                win.videoFolder = videoFolder;              // the video's folder name
                win.mediaServerUrl = mediaServerUrl;        // the media server url
                win.filename = list.selectedItem.filename;  // the file to be played
                win.comments = list.selectedItem.comments;  // the comments left for that
                win.title = list.selectedItem.name+" στις "+list.selectedItem.date; //title of the window

                this.addEventListener(ResizeEvent.RESIZE, window_resize);
                PopUpManager.addPopUp(win,this,true);
                PopUpManager.centerPopUp(win);

            }
        }

【问题讨论】:

    标签: actionscript flex4 popup resize aspect-ratio


    【解决方案1】:

    编辑(12/15): 好的,我尝试了您的代码并添加了一种方法来根据父容器的纵横比强制视频的纵横比。我在 VideoDisplay 组件周围放置了一个 HGroup,并用它来确定视频的大小。如果窗口和视频的大小不同,它还会在弹出窗口中居中显示视频。

    <?xml version="1.0" encoding="utf-8"?>
    <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               close="CloseWindow(event)" autoLayout="true">
    <fx:Script>
        <![CDATA[
            import mx.events.CloseEvent;
            import mx.events.ResizeEvent;
            import mx.managers.PopUpManager;
    
    
            [Bindable]public var mediaServerUrl:String;
            [Bindable]public var videoFolder:String;
            [Bindable]public var filename:String;
            [Bindable]public var comments:String;
    
    
            private var ns:NetStream;
            private var nc:NetConnection;
            private var video:Video;
            private var meta:Object;
    
            private function ns_onMetaData(item:Object):void {
                trace("meta");
                meta = item;
    
                var vidAspectRatio:Number = item.width / item.height;
                var titleWindowAspectRatio:Number = vidContainer.width / vidContainer.height;
    
                // Resize Video object to same size as meta data.
                if ( vidAspectRatio < titleWindowAspectRatio ) // TitleWindow too wide
                {
    
                    video.height = vidContainer.height;
                    video.width = video.height * vidAspectRatio;
                } 
                else if ( vidAspectRatio > titleWindowAspectRatio )  // TitleWindow too tall
                {
                    video.width = vidContainer.width;
                    video.height = video.width / vidAspectRatio;
                } 
                else // TitleWindow and Video have same aspect ratio and fits just right
                {
                    video.width = vidContainer.width;
                    video.height = vidContainer.height;
                }
    
                // Resize UIComponent to same size as Video object.
                myVid.width = video.width;
                myVid.height = video.height;
    
            }
    
            private function fetch_rec():void {
                var nsClient:Object = {};
                nsClient.onMetaData = ns_onMetaData;
    
                nc = new NetConnection();
                nc.connect(null);
                ns = new NetStream(nc);
                ns.client = nsClient;
    
                video = new Video(myVid.width,myVid.height);
                video.attachNetStream(ns);
                video.smoothing=true;
                myVid.addChild(video);
    
                ns.play("../swf/barsandtone.flv");
            }
    
            protected function CloseWindow(event:CloseEvent):void
            {
                ns.close();
                nc.close();
                PopUpManager.removePopUp(this);
    
            }
    
        ]]>
    </fx:Script>
    <s:HGroup id="vidContainer" verticalAlign="middle" horizontalAlign="center" height="100%" width="100%" bottom="50" >
        <mx:VideoDisplay id="myVid" visible="true"
                         autoPlay="true" 
                         creationComplete="fetch_rec()"
                         playheadUpdate="progBar.setProgress(myVid.playheadTime,myVid.totalTime)"/>
    </s:HGroup>
    
    <mx:ProgressBar id="progBar" left="10" right="10" bottom="60" height="10" label="" mode="manual"/>
    <s:Label x="10" bottom="30" text="Σχόλια:"/>
    
    <s:Label x="10" bottom="10" text="{comments}"/>
    </s:TitleWindow>
    

    【讨论】:

    • 让我解释一下...我有一个显示视频缩略图的组件...当您单击时,我已经放置了一个函数launchPopUp,它创建一个调用一个新的窗口组件,我已经制作了一个名为 VideoPopUp。 mxml 和我将其宽度和高度分别设置为 win.width = this.width; win.height = this.height; 在launchPopUp 中。现在在 VideoPopUp 我有视频显示,我将高度设置为 100% 和宽度 = 100% 但是当我执行上述操作时当我只设置其中一个时,我看不到任何名为 scaledmode 的属性,可能它仅在 VideoPlayer 组件中......?该怎么办?有什么想法吗?
    • 尝试设置 width=100%,但删除 height 属性。如果这不起作用,您可以在您的问题中发布 VideoPopUp.mxml 的代码吗?
    • 我花了一些时间摆弄您的代码并找到了可能的解决方案。请参阅我上面发布的代码。
    • 我不知道,但它似乎对我不起作用.. :S 我用来调用此弹出窗口的代码显示在上面的编辑中...也许有问题..
    • 不,我没有收到错误消息,但是当我的主应用程序在我的 15 英寸笔记本电脑上全屏运行时,我的屏幕很宽,弹出窗口的宽度会拉伸,它似乎无法保持纵横比。 . :/
    猜你喜欢
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2013-06-26
    • 2012-04-15
    相关资源
    最近更新 更多