title: WPF Seamless video play back
body: <p>I'm working on a project right now where we are in need of seamless video transition between multiple videos in a WPF application. </p>
  
  <p>A second monitor is being used as a media player, events are being sent to the screen to fire off videos, the video position is then being used to fire events back according to the video hitting specific intervals. The project is using a PRISM so the events are being fired by it's Event Aggregator.</p>
  
  <p>The issue is finding a way of playing Videos in WPF that will accommodate for buffering between videos.  I don't have code examples for methods tried but I have attempted to do this using.</p>
  
  <ul>
  <li>The native WPF Media Element. This was very buggy and most certainly not user friendly. Bad play back and huge gaps between media files. </li>
  <li><a href="http://wpfmediakit.codeplex.com/" rel="nofollow">WPFMediaKit</a> This is probably the best solution so far, video play back is fine with two issues. The media screen stops playing videos at it seems random times and the control goes black. And the transition between videos is about half a second of black.</li>
  <li>Hosting AxWindowsMediaPlayer in a WindowsFormsHost. Play back is great but there is a huge gap between videos, even when running a playlist (This does not happen in Windows Media player so there could be something we are missing.) also as the control is hosted in a WindowsFormsHost I'm not sure if it is possible to keep(Bind) the videos position, and the position event does not appear to be caught.</li>
  <li>GMF Play - Seems to have the same issues as WPFMediaKit except the seen is collapsed rather than the screen going black during transitions.</li>
  </ul>
  
  <p><strong>Edit</strong>
  Media Player Example</p>
  
  <p>Media Element Setup</p>
  
  <pre><code>private void CreateMediaKitElement()
      {
          WpfMediaKit.BeginInit();
          WpfMediaKit.Stretch = Stretch.Fill;
          WpfMediaKit.LoadedBehavior = WPFMediaKit.DirectShow.MediaPlayers.MediaState.Manual;
          WpfMediaKit.MediaEnded += WpfMediaKit_MediaEnded;
          WpfMediaKit.Volume = 0;
          WpfMediaKit.EndInit();
      }
  
  
  private void PlayVideo(string uri, IEnumerable&lt;Interval&gt; intervals)
  {
      // Stop the current Audio track if a new video is being shown.
      AudioElement.Stop();
  
      WpfMediaKit.Stop();
  
  
      // WpfMediaKit = null;
      //Try recreating Element
      WpfMediaKit = new MediaUriElement();
      CreateMediaKitElement();
  
  
      WpfMediaKit.Source = new Uri(uri, UriKind.Relative);
      WpfMediaKit.Play();
  
  }
  </code></pre>
  
  <p>So my question, does anyone know of or have an example of a method to play videos in WPF with a seamless transition between videos?</p>
  
  <p>Thanks in advance,
  Oli</p>