3

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!

Justin
  • 1,249
  • 1
  • 15
  • 37
  • Any way you could post a sample apk and project source (some simplified version if you have business logic in there that's sensitive). Perhaps someone else has actually already run into this issue but if not you can certainly get more eyes on it by posting some example code/project (perhaps github or else just post the apk and project export zip to a server somewhere). – shaunhusain Feb 03 '12 at 03:35
  • I updated it! Thank for your help – Justin Feb 03 '12 at 16:37
  • 1
    I'm going to try and get this running on a Galaxy Nexus (hopefully tonight) I'll let you know how that plays out, thanks for posting some sample code. – shaunhusain Feb 03 '12 at 19:25
  • You also need to set direct and add -swf-version=13 -target-player=11.0 to the compiler to get stage 3d to work (I'm sure you already know this but i just wanted to make a note just in case it's helpful to someone) – Justin Feb 03 '12 at 20:45
  • Just wondering if you ever did try this? – Justin Apr 13 '12 at 18:18
  • I am still working on trying to get stageVideo to work but as a heads up to people reading this i think it has something to do with buffering. – Justin May 03 '12 at 23:45
  • Possible duplicate of [StageVideo on Android Nexus 7 shows a black square](http://stackoverflow.com/questions/26632755/stagevideo-on-android-nexus-7-shows-a-black-square) – Paul Sweatte Nov 27 '15 at 18:13

0 Answers0