Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Volume control in the navipanel

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (04 Apr 2007)
Last edited: hamishwillee (12 Jan 2012)

The CVolumeContainer illustrates how to utilize the navipane volume control in your music player. Ready to use, just add the audio playing/recording

Headers:

#include <aknappUi.h>
#include <aknnavi.h>
#include <aknnavide.h>
#include <avkon.rsg>

Link against:

LIBRARY avkon.lib eikcoctl.lib


NaviVolume_Container.cpp

#include <aknappUi.h>
#include <aknnavi.h>
#include <aknnavide.h>
#include <avkon.rsg>
 
#include "NaviVolume_Container.h"
 
CVolumeContainer::CVolumeContainer(TBool aRecorder, TInt aVolume)
:iRecorder(aRecorder),iVolume(aVolume)
{
}
 
CVolumeContainer::~CVolumeContainer()
{
if(!iNaviPane)
{
CEikStatusPane *sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
iNaviPane = (CAknNavigationControlContainer*)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
}
 
if(iNaviPane)
iNaviPane->Pop(NULL);
 
delete iNaviDecorator;
}
 
void CVolumeContainer::ConstructL(const TDesC& aFileName)
{
CreateWindowL();
 
SetRect(CEikonEnv::Static()->EikAppUi()->ClientRect());
 
CEikStatusPane *sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
iNaviPane = (CAknNavigationControlContainer*)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
 
if(iRecorder)
iNaviDecorator = iNaviPane->CreateVolumeIndicatorL(R_AVKON_NAVI_PANE_RECORDER_VOLUME_INDICATOR);
else
iNaviDecorator = iNaviPane->CreateVolumeIndicatorL(R_AVKON_NAVI_PANE_VOLUME_INDICATOR);
 
STATIC_CAST(CAknVolumeControl*,iNaviDecorator->DecoratedControl())->SetValue(iVolume);
iNaviPane->PushL(*iNaviDecorator);
 
ActivateL();
DrawNow();
 
// add the player construction in here...
}
 
TKeyResponse CVolumeContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
{
TKeyResponse Ret = EKeyWasNotConsumed;
switch (aKeyEvent.iCode)
{
case EKeyRightArrow:
if(iNaviDecorator)
{
iVolume = iVolume + 1;
if(iVolume > 10)
iVolume = 10;
 
STATIC_CAST(CAknVolumeControl*,iNaviDecorator->DecoratedControl())->SetValue(iVolume);
 
// set the volume value for the player in here..
Ret = EKeyWasConsumed;
DrawNow();
}
return(EKeyWasConsumed);
 
case EKeyLeftArrow:
if(iNaviDecorator)
{
iVolume = iVolume - 1;
if(iVolume < 1)
iVolume = 1;
 
STATIC_CAST(CAknVolumeControl*, iNaviDecorator->DecoratedControl())->SetValue(iVolume);
 
// set the volume value for the player in here..
Ret = EKeyWasConsumed;
DrawNow();
}
break;
 
default:
break;
}
 
return Ret;
}
 
 
void CVolumeContainer::Draw(const TRect& /*aRect*/) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
 
// Gets the control's extent
TRect drawRect(Rect());
 
// Clears the screen
gc.Clear(drawRect);
}

NaviVolume_Container.h

class CAknNavigationControlContainer;
class CAknNavigationDecorator;
 
class CVolumeContainer : public CCoeControl
{
public:
~CVolumeContainer();
CVolumeContainer(TBool aRecorder, TInt aVolume);
void ConstructL(const TDesC& aFileName);
 
public:
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
 
private:
void Draw(const TRect& aRect) const;
 
private:
TBool iRecorder;
TInt iVolume;
CAknNavigationControlContainer* iNaviPane;
CAknNavigationDecorator* iNaviDecorator;
};
This page was last modified on 12 January 2012, at 06:15.
47 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×