Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top