0 Replies Latest reply on Jun 13, 2011 3:53 PM by Flash275

    Do not created live video stream on RTMP

    Flash275

      Hello, all.

      Whats wrong in this code:

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="windowedapplication1_applicationCompleteHandler(event)" width="644" height="666">
          <fx:Script>
              <![CDATA[
                  import mx.events.FlexEvent;
                 
                  import org.osmf.events.MediaPlayerStateChangeEvent;
                  import org.osmf.events.TimeEvent;
                 
                  import spark.components.mediaClasses.DynamicStreamingVideoSource;
                 
                  private var nc:NetConnection;
                  private var ns:NetStream;

       

                  var camera:Camera;
                  protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
                  {
                      // TODO Auto-generated method stub
                  }

       

                  private function videoDisplay_creationComplete():void {
                      camera = Camera.getCamera();
                      if (camera) {
                          videoDisplay1.attachCamera(camera);
                          videoDisplay1.autoPlay;
                          SetNetworkStream();
                      }
                      else {
                          ErrorMessage.text += "You dont have a camera.\n";
                      }
                  }
                 
                  import mx.collections.ArrayCollection;
                  [Bindable]private var microphoneList:ArrayCollection;
                  protected var microphone:Microphone;
                 
                  protected function cbMicChoices_creationCompleteHandler(event:FlexEvent):void
                  {
                      microphoneList = new ArrayCollection(Microphone.names);
                      cbMicChoices.selectedIndex=0;
                  }

       

                  private var nsClient:Object;
                  private var video:Video;
                  private var meta:Object;
                  protected function SetNetworkStream():void{
                      nsClient = {};
                      nsClient.onMetaData = ns_onMetaData;
                      nsClient.onCuePoint = ns_onCuePoint;
                      nsClient.onBWDone = ns_onBWDone;
                     
                     
                      nc = new NetConnection();
                      nc.client=nsClient;
                      nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);
                      nc.connect("rtmp://localhost/live");
                  }
                 
                  private function checkConnect (event:NetStatusEvent):void
                  {
                      if (event.info.code=="NetConnection.Connect.Success"){
                          ns = new NetStream(nc);
                          ns.attachCamera(camera,VideoQuality.value);
                          ns.attachAudio(microphone);
                          ns.publish("livestream","live");
                      }
                  }
                 
                 
                  protected function vpCompleteHandler(event:TimeEvent):void {
                      TextArea1.text = "Video complete - restarting."
                  }
                 
                  protected function vpMediaPlayerStateChangeHandler(event:MediaPlayerStateChangeEvent):void {
                      if (event.state == "loading")
                          TextArea1.text = "loading ...";
                      if (event.state == "playing")
                          TextArea1.text = "playing ...";
                  }
                 
                  private function ns_onMetaData(item:Object):void {
                      trace("meta");
                  }
                 
                  private function ns_onCuePoint(item:Object):void {
                      trace("cue");
                  }
                  private function ns_onBWDone():void {
                      trace("BWDone");
                  }
                 
              ]]>
          </fx:Script>
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <s:TileGroup horizontalGap="12" verticalGap="12" left="10" right="10" top="10" bottom="10">
              <mx:Form dropShadowVisible="true" borderAlpha="1.0" borderVisible="true" borderStyle="solid" width="300">
                  <mx:FormItem >
                      <mx:VideoDisplay id="videoDisplay1"
                                       creationComplete="videoDisplay_creationComplete();"
                                       width="200"
                                       height="200"  horizontalCenter="0" verticalCenter="0" dropShadowVisible="false"/>
                  </mx:FormItem>
                  <mx:FormItem >
                      <mx:Button id="RefreshLocalCamera"
                                 label="Refresh local Camera"
                                 click="videoDisplay_creationComplete();" />
                  </mx:FormItem>
                  <mx:FormItem>
                      <s:HSlider id="VideoQuality" width="143" stepSize="1" minimum="0" maximum="100" value="50" />
                      <s:Label text="Quality"/>
                  </mx:FormItem>
              </mx:Form>
              <mx:Form dropShadowVisible="true" borderAlpha="1.0" borderVisible="true" borderStyle="solid" width="300" height="132">
                  <mx:FormHeading label="Remote camera:"/>
                  <mx:FormItem >
                      <s:VideoPlayer id="VideoPlayer1" width="200"  height="200" autoPlay="true"
                                       complete="vpCompleteHandler(event);"
                                       mediaPlayerStateChange="vpMediaPlayerStateChangeHandler(event); ">
                          <s:source>
                              <s:DynamicStreamingVideoSource id="Live1"
                                                             host="rtmp://192.168.0.21:8008/live">
                                  <s:DynamicStreamingVideoItem id="livestream1"
                                                               streamName="livestream"
                                                               bitrate="150" />
                              </s:DynamicStreamingVideoSource>
                          </s:source>
                          </s:VideoPlayer>
                      <s:TextArea id="TextArea1" width="200" height="25"/>
                  </mx:FormItem>
              </mx:Form>
              <mx:Form dropShadowVisible="true" borderAlpha="1.0" borderVisible="true" borderStyle="solid" width="300" height="132">
                  <mx:FormHeading label="Local microphone:"/>
                  <mx:FormItem label="Volume">
                      <s:HSlider width="143"/>
                  </mx:FormItem>   
                  <mx:FormItem >
                      <s:ComboBox id="cbMicChoices" dataProvider="{microphoneList}" selectedIndex="0" dropShadowVisible="true" creationComplete="cbMicChoices_creationCompleteHandler(event)"/>
                  </mx:FormItem>   
              </mx:Form>
              <mx:Form dropShadowVisible="true" borderAlpha="1.0" borderVisible="true" borderStyle="solid" width="300" height="132">
                  <mx:FormHeading label="System message:"/>
                  <mx:FormItem >
                      <s:RichText id="ErrorMessage" text="" />
                  </mx:FormItem>
              </mx:Form>
          </s:TileGroup>
      </s:WindowedApplication>

       

       

      Video in VideoPlayer1 does not play. But play if live video created by Flash Media Live Encoder.

      All my developer environment is described in this page - http://www.vb-net.ru/Flex_Video/index.htm

      please, help