Programmatic access to Windows Phone FM tuner

Windows Phone 7 has the FMRadio class (Microsoft.Devices.Radio namespace) that is ready to use:

FMRadio.Instance.PowerMode = RadioPowerMode.On; 

but… there are couple of things to know:

The first time you will use it, chances are that you will get an UnauthorizedAccessDenied exception with an obscure "Access is denied" message.

The problem is that the Zune software must be closed….  but if you close Zune, now when you try to build or debug (F5 or Ctrl+F5) Visual Studio complains that it can’t deploy to the device anymore: “Zune software is not launched. Retry after making sure that Zune software is launched.”

So… you need to deploy the app to the device and then close Zune, debugging might be a problem as if you hit F5 then close Zune, the app will stop; but instead you can right-click on your project and select “Deploy”:

Now you can close Zune and it should be ok, but the FM Radio only works with headset plugged or you’ll get an error notification. You can check this by code:


    FMRadio fmRadio = FMRadio.Instance;
    fmRadio.PowerMode = RadioPowerMode.On;
    fmRadio.CurrentRegion = RadioRegion.UnitedStates;
    fmRadio.Frequency = 99.5;
    if (FMRadio.Instance.SignalStrength == 0.0)
        MessageBox.Show("Please connect your headset.");
catch (Exception ex)
    MessageBox.Show(String.Format("Error: {0}\nClose the Zune
software or disconnect the phone from your computer."
, ex.Message));


Also check the Marketplace application certification requirements document, as you need to follow some guidelines while your app plays music, like updating the “History” area of the Music hub, or asking the user his permission to play music in background.


Note: I was not able to make FM Radio works in the emulator, some people report that it may take long (minutes) to launch…but for me it keeps telling that headset are not connected.


Download my code sample

No Comments