开发者

Relative Uri works for BitmapImage, but not for MediaPlayer?

This will be simple for you guys:

var uri = new Uri("pack://application:,,,/LiftExperiment;component/pics/outside/elevator.jpg");
imageBitmap = new 开发者_如何学JAVABitmapImage();
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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜