O'Reilly logo

Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® by Robert Fonseca-Ensor, Karli Watson, Nick Lecrenski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TUNING IN TO THE FM RADIO

FM radio functionality is now included on many mobile devices as standard, presumably in an effort to reduce the number of gadgets you need to carry around with you. While there is likely to be an application built into the Windows Phone 7 operating system to control the radio (if present), there is also a very simple API that you can use to do so from within your applications.

image NOTE You should treat FM radio functionality, like vibration functionality, as optional in your code because it is not included in the Windows Phone 7 hardware specification.

To control the radio, you simply need to manipulate an instance of the FMRadio class, which is located in the Microsoft.Devices.Radio namespace. You can get an instance through the FMRadio.Instance property. You can then turn the radio on or off by using the FMRadio.PowerMode property (which you set to RadioPowerMode.On or RadioPowerMode.Off) and change the frequency by using the Frequency property. Setting the frequency will automatically power on the radio if it is off.

You can also control the frequency band in use though the FMRadio.CurrentRegion property, which can be RadioRegion.UnitedStates, RadioRegion.Japan, or RadioRegion.Europe. By doing this, you can ensure that an attempt to tune the frequency to a non-available value will raise an ArgumentException error. It is therefore worth checking for this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required