WP7 play many compressed (mp3, wma etc) audio files simultaneously/dynamically
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.
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.
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.
using Microsoft.Xna.Framework.Media;
void PlaySound(string pathToMp3) {
Song song = Song.FromUri("name", new Uri(pathToMp3, UriKind.Relative));
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
MediaPlayer.Play(song);
}
链接地址: http://www.djcxy.com/p/41788.html
上一篇: MediaElement停止背景音频