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:55, 14 May 2008.

CS000951 - Enabling and disabling defined key sound using CAknKeySoundSystem

From Forum Nokia Wiki


ID CS000951 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::PushContextL(), CAknKeySoundSystem::BringToForeground(), CAknKeySoundSystem::LockContext(),CAknKeySoundSystem::PopContext(), CAknKeySoundSystem::ReleaseContext()

Overview

This code snippet shows how CAknKeySoundSystem is used to enable/disable a defined key sound. EStdKeyDevice3 (the selection key) is used as an example.

This snippet can be self-signed.

MMP file

The following libraries are required:

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

Resource file

#include <eikon.rh>
#include <avkon.rsg>
#include <avkon.rh>
#include <e32keys.h> //EStdKeyDevice3
 
//----------------------------------------------------
//    key sound map to disable selection key sound  
//----------------------------------------------------
//
RESOURCE AVKON_SKEY_LIST r_silent_select_key_list
    {
    list=
        {
        AVKON_SKEY_INFO 
            {
            key = EStdKeyDevice3;
            sid = EAvkonSIDNoSound;
            },
        AVKON_SKEY_INFO
            {
            key = EStdKeyDevice3;
            sid = EAvkonSIDNoSound;
            type = ESKeyTypeLong;
            },
        AVKON_SKEY_INFO
            {
            key = EStdKeyDevice3;
            sid = EAvkonSIDNoSound; 
            type = ESKeyTypeRepeat;
            }
        };
    }


Header file

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

Source file

#include <Tester_0xE0060BB5.RSG> //r_silent_select_key_list
 
#include <aknsoundsystem.h>  // CAknKeySoundSystem
#include <aknappui.h>
 
void CTesterAppView::ConstructL(const TRect& aRect)
    {
//...
    iSilentSelection = EFalse;
    iSoundSystem = static_cast<CAknAppUi*>(
    CEikonEnv::Static()->AppUi() )->KeySounds();
 
    if (!iSoundSystem)
        {
        //pointer to KeySound API object is null
        User::Leave(KErrGeneral);
        }
    }
    
CTesterAppView::~CTesterAppView()
    {
    iSoundSystem = NULL;
    }    
    
// ---------------------------------------------------------------------------
// Disable selection key sound
// ---------------------------------------------------------------------------
//
void CTesterAppView::DisableSelectionKeySoundL()
    { 
    if ( iSoundSystem && !iSilentSelection )
        {
        //load key sound map from resources and push it to the context stack
        iSoundSystem->PushContextL( R_SILENT_SELECT_KEY_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();
        
        iSilentSelection = ETrue;
        }
    }
 
// ---------------------------------------------------------------------------
// Enable selection key sound
// ---------------------------------------------------------------------------
//
void CTesterAppView::EnableSelectionKeySound()
    {
    if ( iSoundSystem && iSilentSelection )
        {
        //release the locked context
        iSoundSystem->ReleaseContext(); 
 
        //pop the pushed context from the context stack
        iSoundSystem->PopContext();
        
        iSilentSelection = EFalse;
        }
    }


Postconditions

The selection key sound is enabled/disabled by calling methods DisableSelectionKeySoundL() and EnableSelectionKeySound().

See also

CS000952 - Enabling and disabling all key sounds using CAknKeySoundSystem

CS000953 - Using customized key sounds with CAknKeySoundSystem

Related Discussions
Thread Thread Starter Forum Replies Last Post
Problem whit sound in a game dsansberro Mobile Java Media (Graphics & Sounds) 3 2006-03-03 11:14
Sound play question!!! Gameryf General Symbian C++ 1 2005-04-13 10:41
GUI with EventHandling from OK key DavidHSR Symbian User Interface 6 2006-05-02 11:16
Sound on Series 60 tuttas Mobile Java General 1 2003-09-30 10:14
nokia sound j2me_raj Mobile Java Media (Graphics & Sounds) 7 2003-12-03 11:16
 
Powered by MediaWiki