相对 Uri 适用于 BitmapImage,但不适用于 MediaPlayer? [英] Relative Uri works for BitmapImage, but not for MediaPlayer?

查看:65
本文介绍了相对 Uri 适用于 BitmapImage,但不适用于 MediaPlayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对你们来说很简单:

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;

=> 在 .jpg 上完美运行构建操作:内容复制到输出目录:始终复制

=> 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();

=> 不适用于具有相同构建操作和复制到输出的 .wav.我在/debug/文件夹中看到该文件..

=> 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();

=> 完美运行..

那么,如何让声音与相对路径一起工作?为什么它不这样工作?如果您需要更多代码或屏幕截图,请告诉我.

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.

谢谢.

推荐答案

pack://application URI 语法用于嵌入"文件,确保媒体文件设置为该格式,或使用 pack://松散"文件的站点来源(复制到 bin 目录).

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 链接

这篇关于相对 Uri 适用于 BitmapImage,但不适用于 MediaPlayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆