Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 11:58, 14 May 2008.

CS000953 - Using customized key sounds with CAknKeySoundSystem

From Forum Nokia Wiki


ID CS000953 Creation date May 14, 2008
Platform S60 3rd Edition, FP1 Tested on devices Nokia N93
Category Symbian C++ Subcategory Multimedia, Audio


Keywords (APIs, classes, methods, functions): CAknKeySoundSystem, CAknAppUi, AVKON_SKEY_LIST, AVKON_SKEY_INFO, CAknAppUi::KeySounds(), CAknKeySoundSystem::AddAppSoundInfoListL(), CAknKeySoundSystem::PushContextL(), CAknKeySoundSystem::BringToForeground(), CAknKeySoundSystem::LockContext(), CAknKeySoundSystem::PopContext(), CAknKeySoundSystem::ReleaseContext()

Overview

This code snippet shows how CAknKeySoundSystem is used to customize the key sounds of an application. The example code customizes arrow key sounds by defining its own AVKON_SKEY_LIST and AVKON_SKEY_INFO structures and uses these when array keys are pressed.

This snippet can be self-signed.

MMP file

The following libraries are required:

LIBRARY  avkon.lib
LIBRARY  eikcore.lib 
LIBRARY  eiksrv.lib

Resource files

  • .hrh file
#ifndef __TESTER_HRH__
#define __TESTER_HRH__
 
//...
 
//arrow sound ids
enum TArrowSoundId
    {
    EUpSoundId = 1,
    EDownSoundId,
    ELeftSoundId,
    ERightSoundId
    };
 
 
#endif // __TESTER_HRH__
  • .rss file
#include <eikon.rh>
#include <avkon.rsg>
#include <avkon.rh>
 
#define KUpArrowSoundFile    "c:\\data\\up.wav"
#define KDownArrowSoundFile    "c:\\data\\down.wav"
#define KLeftArrowSoundFile    "c:\\data\\left.wav"
#define KRightArrowSoundFile    "c:\\data\\right.wav"
 
RESOURCE AVKON_SOUND_INFO_LIST r_arrow_sound_list
    {
    list = 
        {
        // up arrow
        AVKON_SOUND_INFO 
           { 
           sid = EUpSoundId; 
           priority = EAvkonKeyClickPriority;
           preference = EAknAudioPrefDefaultTone;
           file = KUpArrowSoundFile;
           volume = 5;
           },
        // down arrow
        AVKON_SOUND_INFO 
           { 
           sid = EDownSoundId; 
           priority = EAvkonKeyClickPriority;   
           preference = EAknAudioPrefDefaultTone;
           file = KDownArrowSoundFile;
           volume = 5;
           },            
        // left arrow
        AVKON_SOUND_INFO 
            { 
            sid = ELeftSoundId; 
            priority = EAvkonKeyClickPriority;  
            preference = EAknAudioPrefDefaultTone;
            file = KLeftArrowSoundFile;
            volume = 5;
            },
        // right arrow
        AVKON_SOUND_INFO 
            { 
            sid = ERightSoundId; 
            priority = EAvkonKeyClickPriority;
            preference = EAknAudioPrefDefaultTone;
            file = KRightArrowSoundFile;
            volume = 5;
            }                
        };
    }
 
RESOURCE AVKON_SKEY_LIST r_arrow_skey_list
  {
  list=
    {
    AVKON_SKEY_INFO 
      {
      key = EStdKeyUpArrow; 
      sid = EUpSoundId;
      },
    AVKON_SKEY_INFO 
      {
      key = EStdKeyDownArrow; 
      sid = EDownSoundId;
      },    
    AVKON_SKEY_INFO 
      {
      key = EStdKeyLeftArrow; 
      sid = ELeftSoundId;
      },
    AVKON_SKEY_INFO 
      {
      key = EStdKeyRightArrow; 
      sid = ERightSoundId;
      }
    };
  }


Header file

#ifndef __TESTERAPPVIEW_H__
 #define __TESTERAPPVIEW_H__
 
// INCLUDES
#include <coecntrl.h>
 
class CAknKeySoundSystem;
 
class CTesterAppView : public CCoeControl
    {
 //... 
private:    
    CAknKeySoundSystem* iSoundSystem;
    TBool iCustomizedKeySounds;
    };
 
#endif // __TESTERAPPVIEW_H__

Source file

#include <Tester_0xE0060BB5.RSG> //r_arrow_sound_list,r_arrow_skey_list
#include "Tester.hrh" //TArrowSoundId
#include <aknsoundsystem.h>  // CAknKeySoundSystem
#include <aknappui.h>
 
void CTesterAppView::ConstructL(const TRect& aRect)
    {
//...
    iCustomizedKeySounds = EFalse;
    iSoundSystem = static_cast<CAknAppUi*>(
    CEikonEnv::Static()->AppUi() )->KeySounds();
 
    if (!iSoundSystem)
        {
        //pointer to KeySound API object is null
        User::Leave(KErrGeneral);
        }
        
    //install the application-specific set of sound ids 
    TRAPD( error, iSoundSystem->AddAppSoundInfoListL(
           R_ARROW_SOUND_LIST ) );
 
    
    if ((error != KErrNone) && (error != KErrAlreadyExists))
        {
        //install sound ids failed
        User::Leave( error );
        }    
        
        
    //NOTE: it is now also possible to play an installed sound
    //just by calling the PlaySound() method e.g.   
    //iSoundSystem->PlaySound( EUpSoundId );
    //...and stop playing it by calling
    //iSoundSystem->StopSound( EUpSoundId );
        
    }
    
CTesterAppView::~CTesterAppView()
    {
    iSoundSystem = NULL;
    }    
    
// ---------------------------------------------------------------------------
// Disable customized key sounds
// ---------------------------------------------------------------------------
//
void CTesterAppView::DisableCustomizedKeySounds()
    {
    if ( iSoundSystem && iCustomizedKeySounds )
        {
        //release the locked context
        iSoundSystem->ReleaseContext();
        
        //pop the pushed context from the context stack
        iSoundSystem->PopContext();
        
        iCustomizedKeySounds = EFalse;
        }
    }
 
 
// ---------------------------------------------------------------------------
// Enable customized key sounds
// ---------------------------------------------------------------------------
//
void CTesterAppView::EnableCustomizedKeySounds()
    {
    if ( iSoundSystem && !iCustomizedKeySounds )
        {
        //load key sound map from resources and push it to the context stack
        iSoundSystem->PushContextL( R_ARROW_SKEY_LIST );
        
        //tell server to use this context stack for processing sounds
        iSoundSystem->BringToForeground();
        
        //lock this context to the foreground, other BringToForeground() calls 
        //will be ignored until ReleaseContext() is called
        iSoundSystem->LockContext();
        
        iCustomizedKeySounds = ETrue;
        }
    }


Postconditions

If the EnableCustomizedKeySounds() method is called, the customized key sounds are played when the user presses the arrow keys. The default key sounds are played again after the DisableCustomizedKeySounds() method call.

See also

CS000951 - Enabling and disabling defined key sound using CAknKeySoundSystem CS000952 - Enabling and disabling all key sounds using CAknKeySoundSystem

Related Discussions
Thread Thread Starter Forum Replies Last Post
key code of symbian 9 devices tony.blue Symbian User Interface 1 2007-03-02 05:38
Midi Sounds Problem ankur_k Mobile Java Media (Graphics & Sounds) 3 2004-03-12 10:18
How to play the system sounds in an application...??? divyas Symbian Media (Graphics & Sounds) 1 2005-10-17 12:11
DeviceControl 7650 ant01 Mobile Java Tools & SDKs 5 2002-08-12 04:32
How to display image from resources? Juggle4Evr1 Symbian User Interface 13 2008-01-20 11:19
 
Powered by MediaWiki