title: Playing sounds in WPF as a resource
body: <p>First of all, I've searched the site and looked at <a href="https://stackoverflow.com/questions/15145209/how-to-play-a-wpf-sound-file-resource">this</a> but unfortunately it did not help me much.</p>
  
  <p>Whenever I click a frog image that I made, I want to play a .wav file as a resource. Here's my code:</p>
  
  <pre><code>void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
  {
      System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"G:\COSR3S\FrogsAndLilyPads\FrogsAndLilyPads\Sounds\FrogCroak.wav");
      player.Play();
  }
  </code></pre>
  
  <p>Of course this worked but my problem is the directory changes from computer to computer, so I thought I'd have to play it as a resource. I don't know how to do that. I am a fairly new programmer, just to keep in mind.</p>
  
  <p>I tried a few variations based on the aforementioned <a href="https://stackoverflow.com/questions/15145209/how-to-play-a-wpf-sound-file-resource">link</a> and played around with it. Examples:</p>
  
  <pre><code>void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
  {
      Uri uri = new Uri(@"pack://application:,,,/Sounds/FrogCroak.wav");
      var player = new MediaPlayer();
      player.Open(uri);
      player.Play();
  }
  </code></pre>
  
  <p>I also tried doing this, although I thought this one wouldn't work, but I tried it anyway:</p>
  
  <pre><code>void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
  {
      Uri uri = new Uri(@"pack://application:,,,/Sounds/FrogCroak.wav");
      System.Media.SoundPlayer player = new System.Media.SoundPlayer(uri);
      player.Play();
  }
  </code></pre>
  
  <p>I was not sure if the "<code>pack://application:,,,</code>" was something that would refer to the file being played.</p>
  
  <p>I also tried to make it as if it was an image, like so:</p>
  
  <pre><code>void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
  {
      System.Media.SoundPlayer player = new System.Media.SoundPlayer(new Uri(@"pack://application:,,,/Sounds/FrogCroak.wav", UriKind.RelativeOrAbsolute));
      player.Play();
  }
  </code></pre>
  
  <p>So instead of <code>new BitmapImage</code> I did <code>new System.Media.SoundPlayer</code> and only to find out that it wouldn't work that way.</p>
  
  <p>EDIT: I forgot to mention that this worked, but it did not play any sound.</p>
  
  <pre><code>void newFrog_MouseUp(object sender, MouseButtonEventArgs e)
  {
      Uri uri = new Uri(@"pack://application:,,,/Sounds/FrogCroak.wav");
      var player = new MediaPlayer();
      player.Open(uri);
      player.Play();
  }
  </code></pre>
  
  <p>Edit2: The possible duplicate technically didn't solve my problem, but according to the accepted answer it is not possible. Is there any other way I could play the audio using a different method?</p>