Adobe air mobile为什么在启动stageVideo视频时舞台会闪烁?

时间:2012-02-02 19:55:56

标签: android flex mobile air adobe

我正在尝试使用stageVideo在Android平板电脑上播放视频,但任何时候我点击播放并将视频添加到舞台上,应用程序闪烁,然后将视频添加到舞台。然后视频开始全部像素化。然后它就会消失,只需几次跳跃即可开始正常播放。我想知道这是怎么回事?是否有更好的加载视频的方法。仅在flex中使用视频对象时也会发生这种情况 视频存储在本地文件中:/// mnt / sdcard
视频类型为H.264

感谢您的帮助!如果我错过了你需要知道的东西请发表评论,我会编辑我的问题。

以下是视频的视图。 (我正在使用基于视图的移动应用程序)

<?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>

以下是我在网上发现的As类以帮助播放视频(实际上并没有使用太多的视频,因为它在视频结束时会出现一些错误,我需要重写它。我注释掉了那些部分)

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 ) ); 
    } 
} 
}

视频位于本地文件系统中的平板电脑上。
谢谢你的帮助!

0 个答案:

没有答案