Chapter 11. Who Said That?
WHAT'S IN THIS CHAPTER
Playing media using the MediaElement
Playing and combining SoundEffects
Recording audio from the microphone
Integrating into the media hub
Tuning the FM radio
Windows Phone is an amazing playback device for both audio and video. Your application can make use of the rich media playback capabilities offered by Silverlight as well as the XNA audio framework for playing polyphonic sound throughout your application.
In this chapter, you will learn how to integrate audio playback into your application and how you can access the microphone audio stream to do your own audio processing. You'll also see how you can leverage cloud-based services to extend the Windows Phone audio capabilities to do text-to-speech and language translation.
MEDIA PLAYBACK
There are two ways to play media within a Windows Phone application. If you want to do simple video or audio playback, you can add a MediaElement
to your PhoneApplicationPage
and use the Source
property to specify the media to play. Alternatively, you can load an audio file into memory using the SoundEffect
class and then play the sound on demand.
MediaElement
Let's start with a simple example of using the MediaElement
to play back an audio file. Create a new project within Visual Studio using the Windows Phone Application project template and add an audio file (e.g., an mp3 or wav file), making sure that the Build Action
property is set to Content
and the Copy to Output Directory
property is set to Copy ...
Get Professional Windows® Phone 7 Application Development: Building Applications and Games Using Visual Studio, Silverlight®, and XNA® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.