如何同时播放多个mp3/wma文件?
我需要在我的 WP7 应用程序中同时播放多个音效。 我目前使用它处理大约 5 MB 的 wav 文件,而不是用 wma/mp3 编码时的 500kb。
代码的当前部分:
Stream stream = TitleContainer.OpenStream(String.Format("/location/{0}.wav", value)
SoundEffect effect = SoundEffect.FromStream(stream);
effect.Play();
这在循环中效果很好,准备所有效果,然后播放它们。
然而,我真的很想使用 mp3/wma/whatever-codec 来精简我的 xap 文件。
我尝试使用 MediaElement
,但看来您也无法使用它来播放多个文件。此外,XNA MediaPlayer
无法实例化,并且据我所知,无法同时播放多个文件。
我看到的唯一解决方案是,我以某种方式将 mp3
解码为 wav
并将该 Stream
提供给 SoundEffect
。
关于如何实现多重播放有什么想法吗?或者有关如何将 mp3
解码为 wav
的建议?
I have the need to play multiple soundeffects at once in my WP7 app.
I currently have it working with wav files that takes around 5 megabyte, instead of 500kb when coded in wma/mp3.
Current part of the code:
Stream stream = TitleContainer.OpenStream(String.Format("/location/{0}.wav", value)
SoundEffect effect = SoundEffect.FromStream(stream);
effect.Play();
This works great in a loop, preparing all effects, and then playing them.
However, I would really like to use mp3/wma/whatever-codec to slim my xap file down.
I tried to use MediaElement
, but it appears that you also can't use that to play multiple files. Also the XNA MediaPlayer
can't be instantiated, and as far as I experienced can't be made to play multiple files at once.
The only solution I see left is that I somehow decode the mp3
to wav
and feed that Stream
to SoundEffect
.
Any ideas on how to accomplish the multiple playback? Or suggestions on how to decode mp3
to wav
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于转换...抱歉 - 但我认为目前没有任何 api 可用于 WMA 或 MP3 解码。
另外,我认为没有任何 MP3、WMA 或 Ogg 解码器的实现可以在纯 c# 代码中使用 - 我见过的所有解码器都使用 DirectShow 或 PInvoke - 例如,请参阅 C# 音频库。
我个人确实希望音频/视频压缩/解压缩在不久的将来在 WP7 API 中可用 - 但我无法猜测什么时候!
对于一些简单的压缩,您可以尝试诸如发送单声道而不是立体声文件,或者发送 8 位而不是 16 位音频文件 - 这些很容易在手机上转换回 16 位(分辨率明显下降)。
使用像 zip 这样的压缩也可能有助于某些声音效果......但我不认为它会取得巨大成功。
On the conversion... sorry - but I don't think there's any api currently available for WMA or MP3 decoding.
Also, I don't think there are any implementations of MP3, WMA or Ogg decoders which are available in pure c# code - all of them I've seen use DirectShow or PInvoke - e.g. see C# Audio Library.
I personally do expect audio/video compression/decompression to be available at some point in the near future in the WP7 APIs - but I can't guess when!
For some simple compression you can try things like shipping mono instead of stereo files, or shipping 8 bit rather than 16 bit audio files - these are easy to convert back to 16 bit (with obvious loss of resolution) on the phone.
Using compression like zip might also help for some sound effects... but I wouldn't expect it to be hugely successful.