Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

When debugging on an Android device, Video objects sometimes refuse to play a Camera or a NetStream object.

Explorer ,
Jun 03, 2015 Jun 03, 2015

I have been coding in Flash for a while, though I haven't worked a whole lot on AIR Mobile yet.  That being said, when debugging on an Android device via USB, Video objects sometimes work just fine when a Camera or NetStream object is attached, and sometimes they refuse to do anything.  In the case of a NetStream, the audio is also missing  In the case of a NetStream object, if I go to the device's desktop, then come back to the app without ever closing it, then the Video object will suddenly start working.

I have two basic methods of reproducing this:

1. For the Camera:

package

{

    import flash.display.Sprite;

    import flash.display.StageAlign;

    import flash.display.StageScaleMode;

    import flash.events.Event;

    import flash.events.TimerEvent;

    import flash.media.Camera;

    import flash.media.Video;

    import flash.utils.Timer;

    public class CameraExample extends Sprite

    {

        private var m_cam:Camera;

        private var m_vid:Video = new Video();

        private var m_tmr:Timer = new Timer(1000);

   

        public function CameraExample()

        {

            stage ? init() : addEventListener(Event.ADDED_TO_STAGE, init);

            function init(pEvent:Event = null):void {

                // support autoOrients

                stage.align = StageAlign.TOP_LEFT;

                stage.scaleMode = StageScaleMode.NO_SCALE;

           

                m_tmr.addEventListener(TimerEvent.TIMER, onTimer);

                m_tmr.start();

            }

        }

   

        private function onTimer(pEvent:TimerEvent):void

        {

            if (m_cam = Camera.getCamera())

            {

                m_tmr.removeEventListener(TimerEvent.TIMER, onTimer);

                m_tmr.stop();

           

                m_vid.attachCamera(m_cam);

                addChild(m_vid);

                trace("here")

            }

        }

    }

}

2. For the NetStream (this is two programs):

package

{

    import flash.display.Sprite;

    import flash.events.Event;

    import flash.events.NetStatusEvent;

    import flash.events.TimerEvent;

    import flash.media.Camera;

    import flash.media.Microphone;

    import flash.net.NetConnection;

    import flash.net.NetStream;

    import flash.utils.Timer;

  

    public class NetStreamExample1 extends Sprite

    {

        private var m_nc:NetConnection = new NetConnection();

        private var m_ns:NetStream;

      

        private var m_cam:Camera;

        private var m_mic:Microphone;

      

        private var m_tmr:Timer = new Timer(1000);

      

        public function NetStreamExample1()

        {

            m_tmr.addEventListener(TimerEvent.TIMER, onTimer);

            m_tmr.start();

        }

      

        private function onTimer(pEvent:TimerEvent):void

        {

            if (m_cam = Camera.getCamera())

            {

                m_tmr.removeEventListener(TimerEvent.TIMER, onTimer);

                m_tmr.stop();

              

                m_mic = Microphone.getMicrophone();

              

                m_nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusNC);

                m_nc.connect("rtmp://SomeIPAddress/SomeApp/0");

            }

        }

      

        private function onNetStatusNC(pEvent:NetStatusEvent):void

        {

            if (pEvent.info.code == "NetConnection.Connect.Success")

            {

                m_ns = new NetStream(m_nc);

                m_ns.attachCamera(m_cam);

                m_ns.attachAudio(m_mic);

                m_ns.publish("0", "live");

            }

        }

    }

}

And:

package

{

    import flash.display.Sprite;

    import flash.display.StageAlign;

    import flash.display.StageScaleMode;

    import flash.events.Event;

    import flash.events.NetStatusEvent;

    import flash.events.TimerEvent;

    import flash.media.Video;

    import flash.net.NetConnection;

    import flash.net.NetStream;

    import flash.utils.Timer;

  

    public class NetStreamExample2 extends Sprite

    {

        private var m_nc:NetConnection = new NetConnection();

        private var m_ns:NetStream;

      

        private var m_vid:Video = new Video();

      

        private var m_tmr:Timer = new Timer(5000, 1);

      

        public function NetStreamExample2()

        {

            stage ? init() : addEventListener(Event.ADDED_TO_STAGE, init);

            function init(pEvent:Event = null):void {

                // support autoOrients

                stage.align = StageAlign.TOP_LEFT;

                stage.scaleMode = StageScaleMode.NO_SCALE;

              

                addChild(m_vid);

              

                m_nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusNC);

                m_nc.connect("rtmp://SomeIPAddress/SomeApp/0");

            }

        }

      

        private function onNetStatusNC(pEvent:NetStatusEvent):void

        {

            trace("m_nc: " + pEvent.info.code);

            if (pEvent.info.code == "NetConnection.Connect.Success")

            {

                m_ns = new NetStream(m_nc);

                m_ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusNS);

                m_ns.play("0", "live");

              

                m_vid.attachNetStream(m_ns);

              

                m_tmr.addEventListener(TimerEvent.TIMER, onTimer);

                m_tmr.start();

            }

        }

      

        private function onNetStatusNS(pEvent:NetStatusEvent):void

        {

            trace("m_ns: " + pEvent.info.code);

        }

      

        private function onTimer(pEvent:TimerEvent):void

        {

            trace(m_ns.info.videoBytesPerSecond);

        }

    }

}

For the NetStream example, run the first part directly out of the IDE, as a desktop AIR app, and run the second part on the Android device through the IDE through a USB cord.  For the FMS, just add a blank app called "SomeApp" without any code.

In the NetStream example, I can see comparable amounts being traced for m_ns.info.videoBytesPerSecond.  The output when it's working is:

m_nc: NetConnection.Connect.Success

m_ns: NetStream.Play.Reset

m_ns: NetStream.Play.Start

m_ns: NetStream.Video.DimensionChange

~15-20k

And when it's not working, it's:

m_nc: NetConnection.Connect.Success

m_ns: NetStream.Play.Reset

m_ns: NetStream.Play.Start

~15-20k

The output is identical in both cases in the Camera example.  Either example will either succeed or fail at random.

As stated earlier, in the NetStream example, if I run back to the Android device's desktop, then go back to the app without ever closing it, it'll suddenly start working.  In that case, a NetStream.Video.DimensionChange event will be logged when I come back to the app.  However this doesn't work for the Camera example.

Does anyone recognize this or know what is happening, or in particular, a good way to fix it?  This does not happen when running it out of the emulator in the IDE.  I'm using Flash Builder 4.7.  Thanks!

UPDATE:

This will apparently only happen when running in debug mode.

TOPICS
ActionScript
251
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation