Adobe air mobile why does the stage flickers when starting a video a stageVideo?

。_饼干妹妹 提交于 2019-12-23 22:15:36

问题


I am trying to Play a video on a android tablet using stageVideo but any time i click play and add the video to the stage the hole app flickers and then the video is added to the stage. The video then start off being all pixelated. Then it goes away and starts playing properly with only a few jumps. I am wondering what is casing this to happen? Is there a better way to load the video. This also can happen when just using the video object in flex.

The video is stored locally in the file:///mnt/sdcard
The video type is H.264

Thanks for your help! If i missed something that you need to know please comment and I will edit my question.

Here is the view for the video. (i am using a view based mobile App)

<?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="stageVidPage" backKeyPressed="0" xmlns:mx="library://ns.adobe.com/flex/mx"  backgroundAlpha="0" alpha="1">

<fx:Script>
    <![CDATA[
        import ios.iOSStageVideo;
        import mx.core.UIComponent;
        import mx.events.FlexEvent;

        protected function backClick(event:MouseEvent):void
        {
            navigator.pushView(SliderAppHomeView);
        }


        protected function playVideo(event:MouseEvent):void
        {
            var path:String = new String(new File("file:///mnt/sdcard/Movies/Video_test_11.mp4").url); 
            var vid:iOSStageVideo = new iOSStageVideo( path , 1280 , 720 ); 
            vid.addEventListener('videoDone' , videoStop); 

            var container:UIComponent = new UIComponent(); 
            container.width = stage.stageWidth; 
            container.height = stage.stageHeight; 
            addElement( container ); 

            container.addChild( vid ); 
        }

        private function videoStop(e:Event):void {
                //vid.stopVideo(); 
                //container.removeChild( vid ); 
                //removeElement( container ); 
        }
    ]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:actionContent>
    <s:Button click="backClick(event)" label="Back"/>
</s:actionContent>

    <s:Button left="10" bottom="10" label="Play" alpha="1" click="playVideo(event)"/>
</s:View>

Here is the As class i found online to help play the video (really don't use much of it and since it gives some errors when the video ends i will need to rewrite it. I commented out those parts)

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 ){ 
        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, 0, 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": 
                stopVideo(); 
                break; 
            case "NetStream.Buffer.Empty": 
                //do something 
                break; 
            case "NetStream.Buffer.Full": 
                //do something 
                break; 
            case "NetStream.Buffer.Flush": 
                //do something 
                break; 
        } 
    } 

    //stop and clear the video 
    //public, can be called externally 
    public function stopVideo():void{ 
        _ns.close(); 
        _ns.dispose(); 
        dispatchEvent( new Event('videoDone', true ) ); 
    } 
} 
}

The video is located on the tablet in the local file system.
Thank you for any help!

来源:https://stackoverflow.com/questions/9119027/adobe-air-mobile-why-does-the-stage-flickers-when-starting-a-video-a-stagevideo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!