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 ...

Get Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.