Adobe Air Mobile 为什么启动视频 stageVideo 时舞台会闪烁?

2024-04-25

我正在尝试使用 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 ) ); 
    } 
} 
}

该视频位于平板电脑上的本地文件系统中。
感谢您的任何帮助!


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Adobe Air Mobile 为什么启动视频 stageVideo 时舞台会闪烁? 的相关文章

随机推荐