title: Vlc.DotNet.Core taking snapshot while streaming
body: <p>I am using Vlc.DotNet.Core for multicast video streaming. Also, I want to take snapshots. For testing, I am working on a simple program that calling snapshot function for every 2 seconds. However snapshot function is not working, when <code>TakeSnapshot</code> function called, it is not calling <code>OnMediaPlayerSnapshotTaken</code> event. </p>
  
  <p>Besides that, I made a snapshot tests for <code>Vlc.DotNet.Forms</code> library and its working quite well. </p>
  
  <p>The simple code I am working on is given below : </p>
  
  <pre><code>using System;
  using System.IO;
  using System.Threading;
  using System.Threading.Tasks;
  using System.Timers;
  using Vlc.DotNet.Core;
  
  namespace SnapshotTest
  {
      class Program
      {
          static void Main(string[] args)
          {
              VlcStreamerSnapshotText myObject = new VlcStreamerSnapshotText();
  
              myObject.streamFile();
          }
      }
      class VlcStreamerSnapshotText
      {
          System.Timers.Timer aTimer = new System.Timers.Timer();
  
          static Vlc.DotNet.Core.VlcMediaPlayer mediaPlayer;
  
          public bool streamFile(string source = "")
          {
              aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
              aTimer.Interval = 2000;
              aTimer.Enabled = true;
  
              var currentDirectory = Directory.GetCurrentDirectory();
              var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "x86" : "x64"));
  
              var options = new string[]
              {
                  "--no-snapshot-preview",
                  "--no-audio"
                  //"--no-video"
                  // VLC options can be given here. Please refer to the VLC command line documentation.
          };
  
              mediaPlayer = new Vlc.DotNet.Core.VlcMediaPlayer(new DirectoryInfo(libDirectory.FullName), options);
  
              string[] mediaOptions = new string[]
              {
                  ":sout=#duplicate{dst=rtp{sdp=rtsp://127.0.0.1:1000/},dst=display}",
                  ":sout-all",
                  ":sout-keep"
              };
  
              //string[] mediaOptions = new string[] { string.Concat("--sout=#duplicate{dst=rtp{sdp=rtsp://", IpAddress, ":", "1000", "/}} --sout-all --sout-keep") };
  
              mediaPlayer.SetMedia(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov"), mediaOptions);
  
              mediaPlayer.SnapshotTaken += OnMediaPlayerSnapshotTaken;
  
              bool playFinished = false;
              mediaPlayer.PositionChanged += (sender, e) =&gt;
              {
                  Console.Write("\r" + Math.Floor(e.NewPosition * 100) + "%");
              };
  
              mediaPlayer.EncounteredError += (sender, e) =&gt;
              {
                  Console.Error.Write("An error occurred");
                  playFinished = true;
              };
  
              mediaPlayer.EndReached += (sender, e) =&gt;
              {
                  playFinished = true;
              };
  
              Task.Factory.StartNew(() =&gt; mediaPlayer.Play());
              //mediaPlayer.Play();
  
              // Ugly, sorry
              while (!playFinished)
              {
                  Thread.Sleep(TimeSpan.FromMilliseconds(500));
              }
              return true;
          }
  
          ManualResetEvent m_mreSnapshot = new ManualResetEvent(false);
          private readonly object m_snapLock = new object();
          private bool m_SnapshotIsTaken = false;
          public bool GetSnapshot()
          {
              m_SnapshotIsTaken = false;
              if (mediaPlayer == null)
              {
                  return false;
              }
  
              string currentTime = DateTime.Now.ToString("yyyyMMdd_HHmmss");
              string uniqueId = generateID(string.Empty);
              string snapName = string.Format("{0}_{1}.png", currentTime, uniqueId);
  
              string tempFilePathCand = Path.GetTempPath();
  
              if (!tempFilePathCand.EndsWith("\\"))
                  tempFilePathCand = tempFilePathCand + "\\" + snapName;
              else
                  tempFilePathCand = tempFilePathCand + snapName;
  
              FileInfo snapPathInfo = new FileInfo(tempFilePathCand);
              //mediaPlayer.Manager.TakeSnapshot();
              mediaPlayer.TakeSnapshot(snapPathInfo);
  
              m_mreSnapshot.WaitOne(TimeSpan.FromSeconds(2));
              if (m_SnapshotIsTaken)
                  return true;
  
              return false;
          }
  
          private string generateID(string tip)
          {
              return string.Format(@"{0}_{1}", tip, Guid.NewGuid().ToString("N"));
          }
  
          void OnMediaPlayerSnapshotTaken(object sender, VlcMediaPlayerSnapshotTakenEventArgs e)
          {
              mediaPlayer.SnapshotTaken -= OnMediaPlayerSnapshotTaken;
              m_SnapshotIsTaken = true;
              mediaPlayer.SnapshotTaken += OnMediaPlayerSnapshotTaken;
          }
  
          private void OnTimedEvent(object source, ElapsedEventArgs e)
          {
              GetSnapshot();
          }
      }
  }
  </code></pre>
  
  <p>So, What am I missing?</p>