title: How to get stream from ONVIF camera using onvif.org
body: <p>I have successfully used the code that I found in below URL:<br>
  <a href="https://www.codeproject.com/Tips/1192709/ONVIF-PTZ-Control-in-Csharp" rel="nofollow noreferrer">https://www.codeproject.com/Tips/1192709/ONVIF-PTZ-Control-in-Csharp</a></p>
  
  <p>To be able to Pan/Tilt an IP Camera using the ONVIF protocol, where as seen in above URL uses:<br>
  <strong>Address, Namespace<br>
  <a href="http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl" rel="nofollow noreferrer">http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl</a>, OnvifMedia10<br>
  <a href="http://onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl" rel="nofollow noreferrer">http://onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl</a>, OnvifPTZService</strong></p>
  
  <p>As this type of code is very new, I would be very happy for some help how I can get the stream from the IP Camera as well. <em>(I am using a software to look at the stream at the moment)</em>
  <br><br>
  I would need to be able to get the stream also so I later can record/take snapshots.<br><br></p>
  
  <p>I have looked at Chapter 7.1 on this link and I am trying to implement this:<br>
  <a href="https://www.onvif.org/wp-content/uploads/2016/12/ONVIF_WG-APG-Application_Programmers_Guide-1.pdf" rel="nofollow noreferrer">https://www.onvif.org/wp-content/uploads/2016/12/ONVIF_WG-APG-Application_Programmers_Guide-1.pdf</a></p>
  
  <p>I have come up with the below code. But wonder for this line that seems to put the stream to some kind of player called "App". "App" is not compiling and wonder how to put this stream to some kind of player or control?
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>App.DoStreaming(mediaUri.Uri);</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> Streaming streaming;
          public class Streaming
          {
              OnvifMedia10.StreamSetup streamSetup;
              OnvifMedia10.MediaUri mediaUri;
              OnvifMedia10.MediaClient mediaClient;
              String mediaProfileToken = "";
              String ErrorMessage = "";
              bool initialised = false;
  
              public bool Initialise(string cameraAddress, string userName, string password)
              {
                  bool result = false;
                  try
                  {
                      var messageElement = new TextMessageEncodingBindingElement()
                      {
                          MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
                      };
                      HttpTransportBindingElement httpBinding = new HttpTransportBindingElement()
                      {
                          AuthenticationScheme = AuthenticationSchemes.Digest
                      };
                      CustomBinding bind = new CustomBinding(messageElement, httpBinding);
                      mediaClient = new OnvifMedia10.MediaClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/Media"));
                      mediaClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                      mediaClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName;
                      mediaClient.ClientCredentials.HttpDigest.ClientCredential.Password = password;
  
                      var profs = mediaClient.GetProfiles();
                      mediaProfileToken = profs[0].token;
  
                      // setup stream configuration
                      streamSetup = new OnvifMedia10.StreamSetup();
                      streamSetup.Stream = OnvifMedia10.StreamType.RTPUnicast; //"RTP-Unicast";
                      streamSetup.Transport.Protocol = OnvifMedia10.TransportProtocol.UDP; //"UDP";
  
                      // RTP/RTSP/UDP is not a special tunnelling setup (is not requiring)!
                      streamSetup.Transport.Tunnel = null;
  
                      // get stream URI
                      mediaUri = new OnvifMedia10.MediaUri();
                      mediaUri = mediaClient.GetStreamUri(streamSetup, mediaProfileToken);
                      App.DoStreaming(mediaUri.Uri);
  
  
  
                      ErrorMessage = "";
                      result = initialised = true;
                  }
                  catch (Exception ex)
                  {
                      ErrorMessage = ex.Message;
                  }
                  return result;
              }
          }</code></pre>
  </div>
  </div>
  </p>