1 Reply Latest reply on Jul 26, 2006 10:31 PM by raghunathrao

    Need Help - How to stream video using FMS & Flex 2.0?

    clsimeone
      Has anyone streamed video using FLEX 2.0 & FMS (Flash Media Server)? I've been working with all the sample code I can find, especially the FLEX 2.0 samples found in the Adobe documentation, but I'm having a heck of a time getting any of them to work.

      If any one has any working code that streams video using FMS & FLEX 2.0 that I can work with I would greatly appreciate it.

      I did get <mx:VideoDisplay> to work, but I'd like to learn how to stream video via RTMP by creating an AS3 component and instantiating it in a MXML file. My broken code is below.

      Thanks
      Chris S.

      <!-- ============================================= -->
      <!-- THE MXML FILE THAT INSTANTIATES THE AS3 COMPONENT -->
      <!-- ============================================= -->


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" xmlns:ns1="myComponents.*">
      <ns1:NetConnectionExample03 id="nce" />
      </mx:Application>

      <!-- ============================================= -->
      <!-- THE AS3 COMPONENT STRAIGHT FROM ADOBE SAMPLE CODE -->
      <!-- ============================================= -->

      package myComponents
      {
      import flash.display.Sprite;
      import flash.events.NetStatusEvent;
      import flash.events.SecurityErrorEvent;
      import flash.media.Video;
      import flash.net.NetConnection;
      import flash.net.NetStream;
      import flash.events.Event;

      public class NetConnectionExample03 extends Sprite
      {
      private var videoURL:String = "sample.flv";
      private var connection:NetConnection;
      private var stream:NetStream;

      public function NetConnectionExample03()
      {
      connection = new NetConnection();
      connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
      connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
      connection.connect("rtmp://fcs.iknowbetter.com/free/");
      }

      private function netStatusHandler(event:NetStatusEvent):void
      {
      switch (event.info.code)
      {
      case "NetConnection.Connect.Success":
      connectStream();
      break;
      case "NetStream.Play.StreamNotFound":
      trace("Stream not found: " + videoURL);
      break;
      }
      }

      private function securityErrorHandler(event:SecurityErrorEvent):void
      {
      trace("securityErrorHandler: " + event);
      }

      private function connectStream():void
      {
      var stream:NetStream = new NetStream(connection);
      stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
      stream.client = new CustomClient();
      var video:Video = new Video();
      video.attachNetStream(stream);
      stream.play(videoURL);
      addChild(video);
      }
      }
      }

      class CustomClient
      {
      public function onMetaData(info:Object):void {
      trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
      }
      public function onCuePoint(info:Object):void {
      trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
      }
      }
        • 1. Re: Need Help - How to stream video using FMS &amp; Flex 2.0?
          raghunathrao
          Its not really clear, if you want to just display videos (flv's) stored in your FMS or want to do live video streaming (as in using a webcam)...

          1. Viewing FLVs from FMS
          ------------------------------------
          You can directly bind the flv path to the source of your video dispaly like below. Here "rrao01" is that machine in which the FMS resides. Note that the video (here COSA.flv) should be placed in the following directory.
          "<FMS BaseDir>\applications\myVideos\streams\_definst_\COSA.flv"

          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="vertical" >
          <mx:VideoDisplay id="myVD" width="100%" height="100%" source="rtmp://rrao01/myVideos/COSA.flv"/>
          <mx:Button label="Button" click="myVD.load(); myVD.play();"/>
          </mx:Application>