WP7 plays a lot of compressed (mp3, wma, etc.) audio files simultaneously / dynamically

For size reasons, I need to associate a WP7 application with compressed sound (mp3, wma, etc.). How to play them freely / at the same time?

The XNA framework only supports WAV files, so if there is some clean C # code library where you could unzip mp3 / wma / ogg (?) On the fly, the next option will be ...

MediaElement But I do not get good results with MediaElement. It seems that you need to add MediaElement specifically as a tag in xaml, and you cannot use multiple instances (multiple tags). Once I play a specific MediaElement, I cannot play another MediaElement on the same page. I don’t know anything about the restriction in the link (the link is very empty). I also tried to dynamically create MediaElement objects, but that doesn't seem right at all, or I just can't get it to play files at all.

+4
source share
4 answers

In my experience there is currently no good solution for this on WP7. Either you use wavs with XNA, or increase the size of xap, or use mp3 with very limited MediaElement functionality, jeopardizing what you can implement with it.

You might be able to port some C # audio libraries to WP7, I still haven't heard about it, so it can be long.

In one of my applications, I finally decided to go with the wav + XNA combination after playing with various options for a long time.

+2
source

Use the built-in sound compression of the XNA content pipeline!

The default value for the SoundEffect content SoundEffect is the best compression quality (which, apparently, is not compression at all). Set the compression quality to Low and you will get a much smaller file. Or "Medium" for a good balance between size and quality.

To change this parameter, select the .wav file in the solution explorer, press F4 to open the properties window, expand the "Content Processor" node and change the compression quality setting that appears.


Here are the instructions with screenshots:

Create a new WP7 XNA game project (or else get an XNA Content Project)

Create project

Add the wav file to the content project:

Add sound effect

Wav file added

Press F4 with the wav file selected in Solution Explorer to open the properties window.

Content properties

Expand the "Content Processor" node and change the compression quality to the desired setting.

Set compression

The Best setting gives no compression (raw waveform), the Medium and Low settings give a much smaller file.

+3
source
 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); } 
+2
source

You can use MediaElement and set the source to mp3, but this cannot be changed from code as in.

 MediaElement me = sender as MediaElement; me.Source = new Uri( 

as you cannot load resources in the source code. you can use several media elements in your xaml and stop them and start the ones you need. So far, you have decided which files you want to download at compile time.

You can also combine these files into one and play them in a specific place, for example.

 me.Position = new TimeSpan(0, 0, 0, 0, 1); me.Play(); 
+1
source

All Articles