title: streaming laptop webcam to wowza server with juv rtmp client
body: <p>I am recently doing a project to publish video to wowza server.  I am able to publish video from a file with JUV rtmp client api.  But I need to publish video from my laptop webcam directly.  How could I do that?  Please explain with an example or demo.</p>
  
  <p>Main part of my code to stream video file is here:</p>
  
  <pre><code>final NetConnection connection = new NetConnection();
  
      connection.configuration().put(NetConnection.Configuration.INACTIVITY_TIMEOUT, -1);
      connection.configuration().put(NetConnection.Configuration.IO_TIMEOUT, 20 /*milliseconds*/);
  
      connection.addEventListener(new NetConnectionListener());
  
      connection.connect("rtmp://localhost:1935/live");
  
      try
      { 
          Thread.sleep(2000);
      }
      catch (Exception e) {/*ignore*/}
      // wait till connected
  
      System.out.println("then connection: "+connection.connected());
      final MediaStreamController controller = new MediaStreamController();
  
      final String streamFile = "C://media/JUV.FLV";
  
      controller.addListener(new IMediaStreamController.ListenerAdapter()
      {
          @Override
          public void onStart(final long timestamp, final IMediaStream stream)
          {
              System.out.println("onStart: " + timestamp + " " + stream);
          }
  
          @Override
          public void onStop(final long timestamp, final IMediaStream stream)
          {
              System.out.println("onStop: " + timestamp + " " + stream);
  
              if (stream != null)
              {
                  stream.release();
              }
  
              try
              {
                  controller.play(new FlvFileMediaStream(streamFile), -1 /*play the whole file*/);
              }
              catch (Exception e)
              {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void onRelease(final long timestamp)
          {
              System.out.println("onRelease: " + timestamp);
          }
      });
  
      if (!disconnected)
      {
          NetStream stream = new NetStream(connection);
  
          stream.addEventListener(new NetStream.ListenerAdapter()
          {
              @Override
              public void onNetStatus(final INetStream source, final Map&lt;String, Object&gt; info)
              {
                  System.out.println("NetStream#onNetStatus: " + info);
  
                  final Object code = info.get("code");
  
                  if (NetStream.PUBLISH_START.equals(code))
                  {
                      try
                      {   System.out.println("playing: ");
                          controller.play(new FlvFileMediaStream(streamFile), -1 /*play the whole file*/);
                      }
                      catch (Exception e)
                      {
                          e.printStackTrace();
                      }
                  }
              }
          });
  
          stream.attachAudio(new MediaStreamMicrophone(controller));
          stream.attachCamera(new MediaStreamCamera(controller), -1);
  
          stream.publish("stream", NetStream.LIVE);
      }
  
      while (!disconnected)
      {
          try
          {
              Thread.sleep(100);
          }
          catch (Exception e) {/*ignore*/}
      }
  
      connection.close();
  }
  </code></pre>