views:

114

answers:

1

This will be simple for you guys:

var uri = new Uri("pack://application:,,,/LiftExperiment;component/pics/outside/elevator.jpg");
imageBitmap = new BitmapImage();
imageBitmap.BeginInit();
imageBitmap.UriSource = uri;
imageBitmap.EndInit();
image.Source = imageBitmap;

=> Works perfectly on a .jpg with Build Action: Content Copy to Output Directory: Copy always

MediaPlayer mp = new MediaPlayer();
var uri = new Uri("pack://application:,,,/LiftExperiment;component/sounds/DialingTone.wav");
mp.Open(uri);
mp.Play();

=> Does not work on a .wav with the same build action and copy to output. I see the file in my /debug/ folder..

MediaPlayer mp = new MediaPlayer();
var uri = new Uri(@"E:\projects\LiftExp\_solution\LiftExperiment\bin\Debug\sounds\DialingTone.wav");
mp.Open(uri);
mp.Play();

=> Works perfectly..

So, how do I get the sound to work with a relative path? Why is it not working this way? Let me know if you want more code or screenshots.

Thanks.

+1  A: 

The pack://application URI syntax is for "embed" files, make sure the the media file is set to that, or use the pack://siteoforigin for "loose" files (copied to bin directory).

MSDN link

Danny Varod
Then why does it work for the first example with the BitmapImage?
Thomas Stock
heh, it works with this:var uri = new Uri("pack://siteoforigin:,,,/sounds/DialingTone.wav");I had to remove "/LiftExperiment;component"
Thomas Stock