×
Namespaces

Variants
Actions
Revision as of 07:40, 1 August 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Seeking radio station using Radio Utilities Symbian API

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Tested on: Nokia N96, Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition ,FP2
S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
Article
Keywords: Radio Utilities, CRadioUtility, CRadioFmTunerUtility, CRadioPlayerUtility
Created: User:Kbwiki (22 Sep 2010)
Last edited: hamishwillee (01 Aug 2012)

Contents

Overview

This article explains how to seek a radio station using the Radio Utilities API.

Description

The Radio Utilities API can be used to tune the tuner to the speficied frequency (Hz) and start playing that radio station. It can also be used to ramp up the volume.

We can search for a station starting from the currently tuned frequency and search in the direction specified (up or down). If a radio station is found while searching, that station is played.


Note.pngNote: :Radio Utilities API is not part of the public SDK. It can be found in the SDK API Plug-in from 3rd Edition, FP2 onwards. Audio Routing API is also part of SDK API Plug-in.

Solution

Required Capabilities

    ReadUserData

Required Headers

#include <AudioOutput.h> //for audio routing control
#include <radioutility.h> 
#include <radiofmtunerutility.h>
#include <radioplayerutility.h>

Engine to handle radio-related issues

The required classes are:

  CRadioUtility (The Radio Utility)
  CRadioFmTunerUtility (The Tuner Utility)
  CRadioPlayerUtility (The Player Utility)
  CAudioOutput 

Construction of Main Objects

void CMyRadioEngine::ConstructL()
  {
    // create an instance of Radio Utility factory and indicate
    // FM Radio is a primary client
    iRadioUtility = CRadioUtility::NewL( ETrue );
    // Get a tuner utility
    iFmTunerUtility = &iRadioUtility->RadioFmTunerUtilityL( *this );
    // Get a player utility
    iPlayerUtility = &iRadioUtility->RadioPlayerUtilityL( *this );
    iPlayerUtility->GetMaxVolume( iMaxVolume );
    iAudioOutput = CAudioOutput::NewL( *iPlayerUtility );
    // Set audio output to current setting
    CAudioOutput::TAudioOutputPreference outputPreference = 
    CAudioOutput::EPrivate;   
    //Change the outputPreference to CAudioOutput::EPublic to launch radio   
    // with loudspeaker.
    iAudioOutputtype = 0; 
    if (0 == iAudioOutputtype)
    {
     outputPreference = CAudioOutput::ENoPreference;
    }
    else if (1 == iAudioOutputtype)
    {
     outputPreference = CAudioOutput::EPublic;
    }
    #ifndef __WINS
    if ( iAudioOutput )
    {
     iAudioOutput->SetAudioOutputL( outputPreference );
    }
    #endif
    // Assume headset is connected, we'll be notified later if it's not   
    // through MrftoRequestTunerControlComplete callback
    // Asynchronous request to get control of the FM tuner
    iFmTunerUtility->RequestTunerControl();
 }


Implementation of MRadioFmTunerObserver:: MrftoRequestTunerControlComplete

void CMyRadioEngine::MrftoRequestTunerControlComplete(
   TInt aError )
{
switch(aError)
   {
   case KErrNone:
   	{
      CEikonEnv::InfoWinL(_L("Starting Radio"),_L(""));
    //The time interval over which the volume should be increased from zero to
    //the current volume setting = 1 Sec
      iPlayerUtility->SetVolumeRamp(1000000);
    // Asynchronous request to start playing the radio.
    // If radio plays successfully, the user will receive callback method      
    // with MrpoStateChage with ERadioPlayerPlaying and KErrNone.
      iPlayerUtility->Play();
     Tint freq = 98300000; //98.3 MHz freq;
    //Asynchronous request to tune the tuner to the speficied frequency(Hz). 
    // User must be ready to receive callback method MrftoTuneComplete  
      iFmTunerUtility->SetFrequency(freq);
    //Asynchronous request to find a radio station.
    //User must be ready to receive callback method MrftoSeekComplete.
     iFmTunerUtility->StationSeek(ETrue);
        }
       break;
   case KFmRadioErrAntennaNotConnected:
        {
   	CEikonEnv::InfoWinL(_L("Headset not connected"),_L(""));
   	  }
   	break;
   case KErrAlreadyExists:
   	{
   		
   	}
   	break;
   case KFmRadioErrFmTransmitterActive:
   	{
   		 
   	}
   	break;
   case KFmRadioErrOfflineMode:
   	{
   	CEikonEnv::InfoWinL(_L("Offline mode"),_L("Cant Start"));
   	}
   	break;
   default:
   	{
   		
   	}
   }

}

Station Seek Complete Event

// Station seek complete event. This event is asynchronous and is received   
// after a call to CRadioFmTunerUtility::StationSeek.
void CMyRadioEngine::MrftoStationSeekComplete(TInt aError, TInt aFrequency)
   {
   CEikonEnv::InfoWinL(_L("MrftoStationSeekComplete"),_L("station"));
   // If no error then radio tuned to frequency(Hz) of the radio station that 
   // was found 
   if(!aError) 
      {
       iFmTunerUtility->SetFrequency(aFrequency); 
      } 
   else
      {
       CEikonEnv::InfoWinL(_L("Error"),_L("Cant find station"));
      }
    }

Sample application

File:FMRadioEx.zip

This page was last modified on 1 August 2012, at 07:40.
93 page views in the last 30 days.