WP7 同时/动态播放许多压缩(mp3、wma 等)音频文件
由于尺寸原因,我需要将 WP7 应用程序与压缩音频(mp3、wma 等)捆绑在一起。我如何自由/同时玩这些?
XNA 框架仅支持 WAV 文件,因此除非有一个纯 C# 托管代码库可以动态解压缩 mp3/wma/ogg (?),否则下一个选项将是...
MediaElement。但我使用 MediaElement 没有得到好的结果。看来你需要在xaml中专门添加一个MediaElement作为标签,并且不能使用多个实例(多个标签)。一旦我播放某个 MediaElement,我就无法在同一页面上播放另一个 MediaElement。我在参考文献中没有找到任何有关限制的信息(参考文献非常空)。 我还尝试动态创建 MediaElement 对象,但这似乎根本无效,或者我根本无法让它播放文件。
For size reasons I need to bundle a WP7 app with compressed audio (mp3, wma etc). How do I play these freely/simultaneously?
The XNA framework only supports WAV files, so unless there is a pure C# managed code library somewhere to decompress mp3/wma/ogg (?) on the fly, the next option would be...
MediaElement. But I don't get good results with MediaElement. It seems that you need to add a MediaElement specifically as a tag in the xaml, and you can't use several instances (several tags). As soon as I play a certain MediaElement I can't play another MediaElement on the same page. I don't find anything about a restriction in the reference (the reference is very empty).
I also tried dynamically creating MediaElement objects, but that doesn't seem valid at all, or I just cannot get it to play the files at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用内置的 XNA 内容管道音效压缩!
SoundEffect
内容类型的默认设置是“最佳”压缩质量(事实上,这似乎是没有的)完全压缩)。将压缩质量设置为“低”,您将得到一个小得多的文件。或者“中”,以在尺寸和质量之间取得良好的平衡。要更改此设置,请在解决方案资源管理器中选择
.wav
文件,按 F4 打开属性窗口,展开“内容处理器”节点,然后更改显示的压缩质量设置。以下是带有屏幕截图的说明:
创建一个新的 WP7 XNA 游戏项目(或以其他方式获取 XNA 内容项目)
添加
wav
文件添加到内容项目:在解决方案资源管理器中选择
wav
文件时按 F4 以打开属性窗口。展开“内容处理器”节点并将压缩质量更改为所需的设置。
“最佳”设置不提供压缩(原始波形),“中”和“低”设置提供一个小得多的文件。
Use the built-in XNA content pipeline sound effect compression!
The default setting for a
SoundEffect
content type is "Best" compression quality (which appears to, in fact, be no compression at all). Set the compression quality to "Low" and you will get a much, much smaller file. Or "Medium" for a nice balance between size and quality.To change this setting, select your
.wav
file in the solution explorer, press F4 to bring up the properties window, expand the "Content Processor" node, and change the compression quality setting that appears.Here are instructions with screenshots:
Create a new WP7 XNA game project (or otherwise get an XNA Content Project)
Add a
wav
file to the content project:Press F4 with the
wav
file selected in the Solution Explorer to bring up the properties window.Expand the "Content Processor" node and change the compression quality to the desired setting.
A setting of "Best" gives no compression (raw waveform), settings of "Medium" and "Low" give a much smaller file.
根据我的经验,目前 WP7 上没有好的解决方案。您可以将 wav 与 XNA 一起使用并增加 xap 的大小,或者使用 MediaElement 功能非常有限的 mp3,从而影响您可以用它实现的功能。
您也许能够将一些C#音频库移植到WP7,我还没有目前还没有听说过,所以可能可能性不大。
在我的一个应用程序中,在尝试了很长一段时间的不同选项后,我最终决定使用 wav + XNA 组合。
In my experience currently there's no good solution for this on WP7. Either you use wavs with XNA and grow the size of the xap or use mp3s with the very limited MediaElement functionalty, compromising on what you can implement with it.
You might be able to port some C# audio libraries to WP7, I haven't heard of any so far so it might be long shot.
In one of my apps I finally decided to go with the wav + XNA combination after playing around with different options for a good while.
您可以使用
MediaElement
并将源设置为 mp3,但这不能从代码中更改,因为您无法将资源加载到源中。
您可以在 xaml 中使用多个 MediaElements 并停止它们并启动您需要的那些。只要您预先确定要在编译时加载哪些文件即可。
您还可以将这些文件合并为一个并在特定位置播放它们,就像这样。
You could use
MediaElement
and set the source to the mp3, but this cannot be changed from code as in.as you cannot load resources into the source.
you could use multiple MediaElements in your xaml and stop them and start the ones you require. As long as you predetermined which files you wanted to load at compile time.
You could also combine those files into one and play them at a particular location, like so.