<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Red Recondite &#187; WPF</title>
	<atom:link href="http://www.redrecondite.com/blog/category/development/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redrecondite.com/blog</link>
	<description>Red Recondite is slumber with a plunger</description>
	<lastBuildDate>Fri, 23 Oct 2009 01:49:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Playing Video in C#</title>
		<link>http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/</link>
		<comments>http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 20:41:30 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/</guid>
		<description><![CDATA[I have been working on a WPF (Windows Presentation Framework) application using Visual C# 2008 Express.  Even though I am at the Initial Optimism phase of Software Development, and my imagination is running wild, I know that nothing will probably become of this work.
The basic goal is to play videos encoded with a number [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a WPF (Windows Presentation Framework) application using Visual C# 2008 Express.  Even though I am at the Initial Optimism phase of Software Development, and my imagination is running wild, I know that nothing will probably become of this work.</p>
<p>The basic goal is to play videos encoded with a number of different codecs (i.e. h.264, Xvid, and DivX).  So, I thought, before I went into all of the other features that this application will do, I&#8217;ll keep things simple and just play a video with the filename hard-coded.</p>
<p>It&#8217;s the year 2008.  I have the latest Microsoft tools available.  Playing a video can&#8217;t be that difficult, can it?<span id="more-23"></span></p>
<p>1) WPF has a native MediaElement&#8230; that only supports wmv files.</p>
<p>2) Microsoft provides a Windows Media Player ActiveX Control (AxWMPLib), that does not seem to be able to use any codecs.  The status displays &#8220;Locating codec&#8221;&#8230; &#8220;Error downloading codec&#8221;, and only plays the audio for the video file.  Using the example from the Windows SDK has the same result.</p>
<p>3) DirectX 9.0 includes a Video class in Microsoft.DirectX.AudioVideoPlayback&#8230; that throws an exception &#8220;Error in the application&#8221; whenever you try to play a video.  I even downloaded an example and built it in Visual Studio 2003, and that doesn&#8217;t work either.</p>
<p>4)  <a href="http://www.videolan.org/">VideoLAN</a> has a <a href="http://wiki.videolan.org/.Net_Interface_to_VLC">.NET Interface</a>&#8230; stored in a wiki.  I guess the concept of a .zip file to download is too much for some developers.  After copying-and-pasting the interface file-by-file, I built it, and got it to play video in the WPF application (by way of the WindowsFormsHost control).</p>
<pre>    VLanControl.VlcUserControl lVideo = new VLanControl.VlcUserControl();</pre>
<pre>    windowsFormsHost1.Child = lVideo;</pre>
<pre>    lVideo.AddToPlayList( "W:/tv/Curb Your Enthusiasm/curb.3x01 - Chet's Shirt.avi", "Curb", null );</pre>
<pre>    lVideo.Play();</pre>
<p>Hooray!  The video played!  I closed the application, ready to finish this off for good, when I experienced a blue screen of death.</p>
<p>As it turns out, you need to stop the video (and maybe clear the playlist) before you exit.</p>
<pre>    protected override void OnClosing( CancelEventArgs e )
    {
        if ( lVideo != null )
        {
            lVideo.Stop();
            System.Threading.Thread.Sleep( 1000 );
            lVideo.ClearPlayList();
            System.Threading.Thread.Sleep( 1000 );
        }
        base.OnClosing( e );
    }</pre>
<p>Be careful&#8230; in WPF, Microsoft decided to remove support for &#8216;OnClosing&#8217;-type events.  You can add an event handler for Closed, but not Closing.  At first, I had tried to add an event for Closed that would stop the video, but because this happened after the window had closed, I still experienced a blue screen.</p>
<p>Also note that the Sleep statements are absolutely necessary.  I tried to get rid of them once, and tried to wait until the VlcUserControl state was no longer &#8216;Playing&#8217;, but the BSOD decided to appear anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
