在Android平板电脑上使用StageVideo闪烁?

在Android平板电脑上使用StageVideo闪烁?,第1张

概述我有一个stageVideo类,我用它在平板电脑上播放视频,但每次播放视频时,平板电脑屏幕会闪烁几次(变黑然后大约四次左右)我想知道是什么原因造成的这个.当我通过视频播放切换到视图时,它会执行此 *** 作.视频的网址传递到视频mxml视图.我使用的是flex 4.6和 Android平板电脑(EEE变压器素数). package ios { import flash.display.Spri 我有一个stageVIDeo类,我用它在平板电脑上播放视频,但每次播放视频时,平板电脑屏幕会闪烁几次(变黑然后大约四次左右)我想知道是什么原因造成的这个.当我通过视频播放切换到视图时,它会执行此 *** 作.视频的网址传递到视频mxml视图.我使用的是flex 4.6和 Android平板电脑(EEE变压器素数).
package ios {     import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageQuality; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.NetStatusEvent; import flash.events.StageVIDeoAvailabilityEvent; import flash.events.StageVIDeoEvent; import flash.geom.Rectangle; import flash.media.StageVIDeo; import flash.media.StageVIDeoAvailability; import flash.media.VIDeo; import flash.net.NetConnection; import flash.net.NetStream; [Bindable] public class iOsstageVIDeo extends Sprite {     private var vIDeoPath:String;     private var vIDeoWIDth:Number;     private var vIDeoHeight:Number;     private var _sv:StageVIDeo;     private var _vd:VIDeo;     private var _obj:Object;     private var _ns:NetStream;     public function iOsstageVIDeo( path:String,w:Number,h:Number ):voID    {         vIDeoPath = path;         vIDeoWIDth = w;         vIDeoHeight = h;         addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);     }     //stage is ready     private function onAddedToStage(e:Event):voID    {         stage.scaleMode = StageScaleMode.NO_SCALE;         stage.align = StageAlign.top_left;         var nc:NetConnection = new NetConnection();         nc.connect(null);         _ns =  new NetStream(nc);         _obj = new Object();         _ns.clIEnt = _obj; _ns.bufferTime = 2;         _ns.clIEnt = _obj;         _obj.onMetaData = MetaData;         _sv = stage.stageVIDeos[0];         _sv.vIEwPort = new Rectangle(0,42,vIDeoWIDth,vIDeoHeight );         _sv.attachNetStream(_ns);         playVIDeo();     }     //vIDeo is ready,play it     //public,can be called externally     public function playVIDeo():voID{         _ns.play( vIDeoPath );         _ns.addEventListener(NetStatusEvent.NET_STATUS,vIDeoStatus);     }     //required Metadata for stagevIDeo,even if not used     private function MetaData(info:Object):voID{ }     //get vIDeo status     private function vIDeoStatus(e:NetStatusEvent):voID{         switch(e.info.code){             case "NetStream.Play.StreamNotFound":                 //do something                 break;             case "NetStream.Play.Start":                 //do something                 break             case "NetStream.Play.Stop":                 //do something                trace('the vIDeo has ended');                stopVIDeo();                break;             case "NetStream.Buffer.Empty":                 //do something                 break;             case "NetStream.Buffer.Full":                 //do something                 break;             case "NetStream.Buffer.Flush":                 //do something                 break;             case "NetStream.Play.Complete":                //do something                 break;        }     }     //stop and clear the vIDeo     //public,can be called externally     public function stopVIDeo():voID{          trace("StopVIDeo is ran.");        _ns.close();        _ns.dispose();         dispatchEvent( new Event('vIDeodone',true ) );     }     public function stopVIDeoBack():voID {        _ns.close();        _ns.dispose();     }}

}

以下是我在视频完成时播放视频的视图代码

<?xml version="1.0" enCoding="utf-8"?><s:VIEw xmlns:fx="http://ns.adobe.com/mxml/2009"     xmlns:s="library://ns.adobe.com/flex/spark" title="" backgroundAlpha="0" creationComplete="init(event)" addedToStage="onAddedToStage(event)"  ><fx:Script>    <![cdaTA[        import ios.iOsstageVIDeo;        import mx.core.UIComponent;        import mx.events.FlexEvent;        protected var path:String = new String("");         protected var backPage:String = new String("");        protected var vID:iOsstageVIDeo = new iOsstageVIDeo( path,1280,720 );        private var arr:Array;        //protected var vID:iOsstageVIDeo;         protected var container:UIComponent = new UIComponent();         protected function init(event:FlexEvent):voID        {            // Sets up the back button to back to the right slIDe            arr =  data as Array;            trace(data);            path = String(arr[0]);            backPage = String(arr[1])             //creates the vIDeo            vID = new iOsstageVIDeo( path,720 );            loadVIDeo();            //takes out the trash when the back button is hit so the stage vIDeo is ready when the new vIEw is loaded            stage.addEventListener("keyDown",handlebuttons,false,1);            stage.addEventListener("keyUp",1);        }        overrIDe public function createReturnObject():Object {            var returnedobject:Object = new Object();            returnedobject.myValue = arr[2];            trace("arr[2] ->" + arr[2])            return returnedobject;        }        protected function loadVIDeo():voID        {            //loades the vIDeo            vID.addEventListener('vIDeodone',vIDeoStop);             container.wIDth = stage.stageWIDth;             container.height = stage.stageHeight;             addElement( container );             container.addChild( vID );         }        protected function playVIDeo(event:MouseEvent):voID        {            vID.playVIDeo();        }        private function vIDeoStop(e:Event):voID {                //removes container                container.removeChild( vID );                 removeElement( container );                 navigator.popVIEw();        }        private function removeEverything():voID {            vID.stopVIDeoBack();            try            {                container.removeChild( vID );                 removeElement( container );            }             catch(error:Error)             {                trace("error with container");            }        }        protected function onAddedToStage(event:Event):voID        {                           if (stage.autoOrIEnts) {                stage.removeEventListener(StageOrIEntationEvent.ORIENTATION_CHANGING,orIEntationChanging);                stage.addEventListener(StageOrIEntationEvent.ORIENTATION_CHANGING,orIEntationChanging,100,true);            }        }        private function orIEntationChanging(event:StageOrIEntationEvent):voID {            event.stopImmediatePropagation();            if (event.afterOrIEntation == StageOrIEntation.ROTATED_left  || event.afterOrIEntation == StageOrIEntation.ROTATED_RIGHT) {                event.preventDefault();             }           }        protected function handlebuttons(event:KeyboardEvent):voID        {            if (event.keyCode == Keyboard.HOME) {                // Handle Home button.            }            else if (event.keyCode == Keyboard.BACK) {                // Hanlde back button.                removeEverything();            }        }    ]]></fx:Script><fx:Declarations>    <!-- Place non-visual elements (e.g.,services,value objects) here --></fx:Declarations></s:VIEw>

编译器参数

-locale en_US-swf-version=13 -target-player=11.0-define CONfig::LOGGING false -define CONfig::FLASH_10_1 true

添加了更新代码以使StageVIDeoEvent侦听器简化为一个视图(也知道renderMode设置为直接)

<?xml version="1.0" enCoding="utf-8"?><s:VIEw xmlns:fx="http://ns.adobe.com/mxml/2009"     xmlns:s="library://ns.adobe.com/flex/spark" title="vIDeo" backgroundAlpha="0" creationComplete="init(event)" ><fx:Script>    <![cdaTA[        import mx.core.UIComponent;        protected var vIDeoPath:String = new String("vIDeo.mp4");         private var vIDeoWIDth:Number = 1280;        private var vIDeoHeight:Number = 680;         private var stageVIDeoAvail:Boolean;        private var sv:StageVIDeo;        private function init(e:Event):voID {            trace("ran one");            onAddedToStage();         }        private function onAddedToStage():voID {            trace('test');            stage.scaleMode = StageScaleMode.NO_SCALE;            stage.align = StageAlign.top_left;                stage.addEventListener(StageVIDeoAvailabilityEvent.STAGE_VIDEO_AVAILABIliTY,onStageVIDeoAvailability);        }        private function onStageVIDeoAvailability( e : StageVIDeoAvailabilityEvent ) : voID        {            if (e.availability == StageVIDeoAvailability.AVAILABLE){                stageVIDeoAvail = true;                initVIDeo();            } else {                stageVIDeoAvail = false;            }        }        private function initVIDeo():voID        {            var obj:Object = new Object();            var nc:NetConnection = new NetConnection();            nc.connect(null);            var ns:NetStream = new NetStream(nc);            ns.clIEnt = obj;            if(stageVIDeoAvail)            {                sv = stage.stageVIDeos[0];                sv.addEventListener(StageVIDeoEvent.RENDER_STATE,onRender);                sv.attachNetStream(ns);                trace('available');            }            else            {                var vID:VIDeo = new VIDeo(vIDeoWIDth,768);                addChild(vID);                vID.attachNetStream(ns);                trace('not');            }            ns.play( vIDeoPath );        }        private function onRender(e:StageVIDeoEvent):voID        {            sv.vIEwPort = new Rectangle(0,768);        }        public function onMetaData(e:Object):voID        {        }        public function onXMPData(e:Object):voID        {        }    ]]></fx:Script><fx:Declarations>    <!-- Place non-visual elements (e.g.,value objects) here --></fx:Declarations></s:VIEw>

这个应用程序中唯一的另一个视图只有一个带navigator.pushVIEw的按钮(copyofvIDeo,null,null);当点击按钮时,屏幕闪烁,然后视频播放.

解决方法 闪烁的一个可能原因是,在调用_ns.play()之前,您不会侦听 StageVideo可用性.通过收听 StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY,您可以管理获得和失去StageVIDeo.

代替

private function onAddedToStage(e:Event):voID{     ...    _sv = stage.stageVIDeos[0];     _sv.vIEwPort = new Rectangle(0,vIDeoHeight );     _sv.attachNetStream(_ns);     playVIDeo(); }

做这个

private function onAddedToStage(e:Event):voID    {        stage.addEventListener( StageVIDeoAvailabilityEvent.STAGE_VIDEO_AVAILABIliTY,onStageVIDeoAvailability );    }    private function onStageVIDeoAvailability( event : StageVIDeoAvailabilityEvent ) : voID    {        var available : Boolean = (event.availability == StageVIDeoAvailability.AVAILABLE);        ...        if ( available )        {            addStageVIDeo();        }        else        {            //implement an alternative e.g. addRegularVIDeo();        }        playVIDeo();    }

Adobe Developer Connection在本教程中讨论了如何监听StageVIDeo的可用性:

Getting started with stage video

本教程提供了一些代码示例:

Creating a StageVideo Test in FDT with Flex 4.5 and FlashPlayer 10.2

总结

以上是内存溢出为你收集整理的在Android平板电脑上使用StageVideo闪烁?全部内容,希望文章能够帮你解决在Android平板电脑上使用StageVideo闪烁?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1135426.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存