Using XNA libraries in your Silverlight Windows Phone 7 applications
| Comments- | Posted in
- silverlight
- xaml
- ria
- xna
- wp7dev
- wp7
- windows phone
- translator
- windows phone 7
I recently got an inquiry to my Microsoft Translator sample on if this would work with the Silverlight in the Windows Phone 7 SDK. I hadn’t tried it before, so I created a sample Windows Phone 7 application and copied the code over. I used a basic UI to mock up the similarities:
And then clicked the button. The text translated fine, but no audio. I didn’t get any warnings that the WaveMSS code sample I was using wouldn’t work. Then I remembered about XNA.
NOTE: I actually think this is a bug in PCM audio and MediaStreamSource and have been having a dialog with the team about it.
In Windows Phone 7 your Silverlight applications can use some XNA Game Framework APIs. A big component of games is audio! Enter SoundEffect. I added a reference to Microsoft.Xna.Frameowkr and changed my OnSpeakCompleted from:
1: void OnSpeakCompleted(object sender, TimHeuer.Silverlight.SpeakCompletedEventArgs e)
2: {
3: WaveMSS.WaveMediaStreamSource mss = new WaveMSS.WaveMediaStreamSource(e.AudioTranslation);
4: PlayMe.SetSource(mss);
5: }
to:
1: void OnSpeakCompleted(object sender, TimHeuer.Silverlight.SpeakCompletedEventArgs e)
2: {
3: SoundEffect se = SoundEffect.FromStream(e.AudioTranslation);
4: se.Play();
5: }
Notice it is still 2 lines of code :-). I don’t need a MediaElement for the audio palyback because I can use the same libraries that XNA uses for audio (and in some instances this will be better for you for looping audio, etc.).
Very cool that Silverlight and XNA can share some libraries in a single application!
Please enjoy some of these other recent posts...
Comments