我如何将 pack uri 资源与媒体播放器一起使用?

发布于 2024-09-19 04:21:14 字数 349 浏览 10 评论 0原文

我有一些非常简单的代码,只需要播放指定音量的声音,如下所示:

var mp = new MediaPlayer();
mp.Open(uri);
mp.Volume = volume;
mp.Play();

出现问题是因为这是 Prism 模块的一部分。我不知道执行程序集将在哪里,因此我无法使用相对 Uri 或 siteoforigin,并且 MediaPlayer 不理解 pack Uri 语法。

我的程序集根目录中有一个名为“notify.wav”的资源 wav 文件,但我无法通过 Uri 将其传递到 MediaPlayer,也看不到任何其他方式来加载它。

如何播放该文件?

I have some very simple code which just needs to play a sound with a specified volume, as follows :

var mp = new MediaPlayer();
mp.Open(uri);
mp.Volume = volume;
mp.Play();

The problem arises because this is part of a Prism module. I don't know where the executing assembly is going to be so I can't use a relative Uri or siteoforigin and MediaPlayer doesn't understand the pack Uri syntax.

I have a resource wav file at the root of my assembly called "notify.wav", but I have no way to pass it into MediaPlayer via a Uri and can't see any other way to load it.

How do I play the file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苍暮颜 2024-09-26 04:21:45

使用 ContentResolver 类从设备检索歌曲并捕获包含(标题、文章、专辑等的 TextView)的 Song.XML。此 XML 随后使用 Adapter 类嵌入到 MainActivity XML(包括 ListView)中,然后您可以调用 onClick(Song.XML) 来播放 MainActivity XML 上的歌曲(设置 URI ),稍后您可以设置 Seekber、Next、Previous 和 Play功能。
如果您愿意,我会给您完整的代码,但我正在尝试使用新的 UI 设计和类文件播放另一个 Activity 中的歌曲,仍在搜索中。

Use ContentResolver class to retrieve the songs from the device and catch with Song.XML that include (TextViews for Title, Article, Album, etc). This XML is later embedded into the MainActivity XML(including ListView) using Adapter class and then you can call onClick(Song.XML) to play the songs (Setting URI ) on MainActivity XML, later you can set Seekber, Next, Previous and Play function.
If you want, I will give you full codes but I am trying to play a song from another Activity using a new UI design and class file, still searching.

錯遇了你 2024-09-26 04:21:42

恐怕媒体播放器不支持包 URI。

您是否尝试过Directory.GetCurrentDirectoryEnvironment.CurrentDirectory

I’m afraid Media player does not support pack URI.

Have you tried Directory.GetCurrentDirectory or Environment.CurrentDirectory?

江城子 2024-09-26 04:21:37

首先,您应该声明一个变量,该变量是媒体文件夹路径的字符串。该变量保存路径。就像:

string url = @"C:\Users\Alico\Documents\visual studio 2010\Projects\WpfBrushesTest\WpfBrushesTest\Dido - Thank You.mp4";

然后

mp.Open(new Uri(url,UriKind.Relative));

First you should declare a variable that is string for your media folder's path. This variable holds the path. just like:

string url = @"C:\Users\Alico\Documents\visual studio 2010\Projects\WpfBrushesTest\WpfBrushesTest\Dido - Thank You.mp4";

and then

mp.Open(new Uri(url,UriKind.Relative));
缺⑴份安定 2024-09-26 04:21:32

由于资源是嵌入的并且 MediaPlayer 不支持 pack uri,因此您需要以流的形式读取资源并将其写入文件。然后您应该能够根据需要将文件加载到播放器中。

我会将文件写入我的应用程序目录,以便从程序集中提取后,您可以直接引用该文件。

希望这有帮助

Since the resource is embedded and the MediaPlayer doesn't support pack uri, you'll need to read the resource in as a stream and write it out to file.You should then be able to load the file into the player as necessary.

I would write the file to my applications directory so that once extracted from the assembly, you can just reference the file directly.

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文