title: Why does MediaPlayer silently fail if started before rendering has occurred?
body: <p>I found this odd behavior with <code>MediaPlayer</code> by accident while helping someone with a problem and I want to see if any WPF guru's can explain it. I understand the below example is not practical, but it best demonstrates the behavior. </p>
  
  <p>Lets say I throw a <code>MediaPlayer</code> in the MainWindow constructor and try to start it.</p>
  
  <pre><code>public MainWindow()
  {
      InitializeComponent();
      MediaPlayer mp = new MediaPlayer();
      mp.Open(new Uri("Be Free.mp3", UriKind.Relative));
      mp.Play();
  }
  </code></pre>
  
  <p>The <code>MediaPlayer</code> will silently fail and you will hear no music play. Now here is where things get interesting. Let's say we throw an <code>OpenFileDialog</code> in there before we start playing. </p>
  
  <pre><code>public MainWindow()
  {
          InitializeComponent();
          MediaPlayer mp = new MediaPlayer();
          mp.Open(new Uri("Be Free.mp3", UriKind.Relative));
  
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.ShowDialog();
  
          mp.Play();
  }
  </code></pre>
  
  <p>The music will begin to play with no problem. You don't even have to select a file, you can just Cancel the Dialog and it will work.</p>
  
  <p>For reference, I am <code>Microsoft.Win32.OpenFileDialog</code>. Can anyone explain how activation of this allows the <code>MediaPlayer</code> to work?</p>