1 Reply Latest reply on Jul 9, 2008 4:26 AM by SeaBream

    AIR strangeness with playing video

    SeaBream
      I've come across something strange with playing local video with AIR 1.1 (FlashCS3, Windows XP)
      If I use this code to play a video
      // AS3
      var myVideo:Video = new Video();
      addChild(myVideo);
      var nc:NetConnection = new NetConnection();
      nc.connect(null);
      var ns:NetStream = new NetStream(nc);
      myVideo.attachNetStream(ns);
      ns.play("test1.flv");

      If works fine if I compile for Flash 9 but if I compile for AIR I get a error:
      "Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on flash.net.NetStream and there is no default value."

      Adding a meta data handler like this fixes it:
      // AS3
      var customClient:Object = new Object();
      customClient.onMetaData = metaDataHandler;

      var myVideo:Video = new Video();
      addChild(myVideo);

      var nc:NetConnection = new NetConnection();
      nc.connect(null);
      var ns:NetStream = new NetStream(nc);
      ns.client = customClient;
      myVideo.attachNetStream(ns);
      ns.play("cell1.flv");


      function metaDataHandler(infoObject:Object):void {
      trace("metaData");
      }
        • 1. Re: AIR strangeness with playing video
          SeaBream Level 1
          Ok, I've found more playing video in AIR strangeness: (Flash CS3, Windows XP)

          Run this code and make sure that "flawed.flv" is a file which has a .flv ending but isn't actually in flv format
          var nc:NetConnection = new NetConnection();
          nc.connect(null);
          var ns:NetStream = new NetStream(nc);
          var vid:Video = new Video(320, 240);
          this.addChild(vid);
          vid.attachNetStream(ns);
          ns.play("flawed.flv");
          ns.addEventListener(NetStatusEvent.NET_STATUS, netstat);
          function netstat(stats:NetStatusEvent)
          {
          trace(stats.info.code);
          }
          var netClient:Object = new Object();
          netClient.onMetaData = function(meta:Object)
          {
          trace(meta.duration);
          };
          ns.client = netClient;


          When compiling for Flash 9 the net status event kicks in and you get a "NetStream.Play.FileStructureInvalid"
          message. When compiling for AIR nothing happens at all.

          Ho hum.