javauis/mmapi_akn/volumekeys/src/cmmaglobalvolume.cpp
branchRCL_3
changeset 24 6c158198356e
parent 14 04becd199f91
equal deleted inserted replaced
23:e5618cc85d74 24:6c158198356e
    70 // CMMAGlobalVolume::AddPlayerL
    70 // CMMAGlobalVolume::AddPlayerL
    71 // ---------------------------------------------------------------------------
    71 // ---------------------------------------------------------------------------
    72 //
    72 //
    73 void CMMAGlobalVolume::AddPlayerL(CMMAPlayer* aPlayer)
    73 void CMMAGlobalVolume::AddPlayerL(CMMAPlayer* aPlayer)
    74 {
    74 {
       
    75     DEBUG("CMMAGlobalVolume: AddPlayerL +");
    75     // Find if the player has a volume control
    76     // Find if the player has a volume control
    76     CMMAVolumeControl* control = FindVolumeControl(aPlayer);
    77     CMMAVolumeControl* control = FindVolumeControl(aPlayer);
    77 
    78 
    78     // Ignore adding new player if it does not support volume control
    79     // Ignore adding new player if it does not support volume control
    79     if (control)
    80     if (control)
    80     {
    81     {
    81         TMMAPlayerHolder playerHolder;
    82         TMMAPlayerHolder playerHolder;
    82         // Create new volume control and level index pair
    83         // Create new volume control and level index pair
    83         playerHolder.iVolumeControl = control;
    84         playerHolder.iVolumeControl = control;
    84         playerHolder.iVolumeIndex = control->AddLevelL();
    85         playerHolder.iVolumeIndex = control->AddLevelL();
       
    86         DEBUG_INT2("CMMAGlobalVolume: AddPlayerL : iVolumeIndex = %d and iLevel = %d",playerHolder.iVolumeIndex,iLevel);
    85         playerHolder.iPlayer = aPlayer;
    87         playerHolder.iPlayer = aPlayer;
    86         // Set current volume level for the control
    88         // Set current volume level for the control
    87         control->SetVolumeLevelL(playerHolder.iVolumeIndex, iLevel);
    89         control->SetVolumeLevelL(playerHolder.iVolumeIndex, iLevel);
       
    90         // To set the initial Global Volume for each player so that 
       
    91         // it will not post any event during the transition to realized state if there 
       
    92         // is no change in the global volume between player creation and realization.
       
    93         control->InitializeGlobalVolumeLevel(iLevel);
    88         // Add created pair to the control list
    94         // Add created pair to the control list
    89         iControlList.AppendL(playerHolder);
    95         iControlList.AppendL(playerHolder);
    90     }
    96     }
       
    97     
       
    98     DEBUG("CMMAGlobalVolume: AddPlayerL -");
    91 }
    99 }
    92 
   100 
    93 // ---------------------------------------------------------------------------
   101 // ---------------------------------------------------------------------------
    94 // CMMAGlobalVolume::RemovePlayer
   102 // CMMAGlobalVolume::RemovePlayer
    95 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
    96 //
   104 //
    97 void CMMAGlobalVolume::RemovePlayer(CMMAPlayer* aPlayer)
   105 void CMMAGlobalVolume::RemovePlayer(CMMAPlayer* aPlayer)
    98 {
   106 {
       
   107     DEBUG("CMMAGlobalVolume: RemovePlayer +");
    99     // Find if the player has a volume control
   108     // Find if the player has a volume control
   100     CMMAVolumeControl* control = FindVolumeControl(aPlayer);
   109     CMMAVolumeControl* control = FindVolumeControl(aPlayer);
   101 
   110 
   102     // Ignore adding new player if it does not support volume control
   111     // Ignore adding new player if it does not support volume control
   103     if (control)
   112     if (control)
   104     {
   113     {
   105         // Check that if this type of volume control can be found from
   114         // Check that if this type of volume control can be found from
   106         // the control list and remove it
   115         // the control list and remove it
   107         TInt count(iControlList.Count());
   116         TInt count(iControlList.Count());
       
   117         DEBUG_INT("CMMAGlobalVolume: RemovePlayer :No of CMMAVolumeControl instances = %d",count);
       
   118                 
   108         for (TInt i(0); i < count; i++)
   119         for (TInt i(0); i < count; i++)
   109         {
   120         {
   110             const TMMAPlayerHolder& holder = iControlList[ i ];
   121             const TMMAPlayerHolder& holder = iControlList[ i ];
   111             if (control == holder.iVolumeControl)
   122             if (control == holder.iVolumeControl)
   112             {
   123             {
       
   124             DEBUG("CMMAGlobalVolume: RemovePlayer  removing the instance of CMMAVolumeControl from the list");
   113                 iControlList.Remove(i);
   125                 iControlList.Remove(i);
   114                 break;
   126                 break;
   115             }
   127             }
   116         }
   128         }
   117     }
   129     }
   122 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   123 //
   135 //
   124 void CMMAGlobalVolume::VolumeUp()
   136 void CMMAGlobalVolume::VolumeUp()
   125 {
   137 {
   126     DEBUG_INT("THREADID = %d : CMMAGlobalVolume: VolumeUp: +", RThread().Id());
   138     DEBUG_INT("THREADID = %d : CMMAGlobalVolume: VolumeUp: +", RThread().Id());
       
   139     DEBUG_INT("CMMAGlobalVolume: VolumeUp : iLevel = %d", iLevel);
   127     // Adjust volume if midlet is in foreground and the volume level value
   140     // Adjust volume if midlet is in foreground and the volume level value
   128     // is not too high, in this case it cannot be set over KMMAVolumeMaxLevel
   141     // is not too high, in this case it cannot be set over KMMAVolumeMaxLevel
   129     if (iForeground->IsForeground() && (iLevel < KMMAVolumeMaxLevel))
   142     if (iForeground->IsForeground() && (iLevel < KMMAVolumeMaxLevel))
   130     {
   143     {
   131         DEBUG("CMMAGlobalVolume: VolumeUp: Volume up");
   144         DEBUG("CMMAGlobalVolume: VolumeUp: Volume up");
   132         // Check that the current volume level is not increased too much
   145         // Check that the current volume level is not increased too much
   133         TInt level =
   146         TInt level =
   134             iLevel > (KMMAVolumeMaxLevel - KMMAVolumeLevelStep) ?
   147             iLevel > (KMMAVolumeMaxLevel - KMMAVolumeLevelStep) ?
   135             KMMAVolumeMaxLevel - iLevel : iLevel + KMMAVolumeLevelStep;
   148             KMMAVolumeMaxLevel - iLevel : iLevel + KMMAVolumeLevelStep;
   136         // Increase level by new value
   149         // Increase level by new value
       
   150         DEBUG_INT("CMMAGlobalVolume: VolumeUp : effective volume to be set to player = %d", level);
   137         SetControlVolumeLevels(level);
   151         SetControlVolumeLevels(level);
   138     }
   152     }
   139     DEBUG("CMMAGlobalVolume: VolumeUp: -");
   153     DEBUG("CMMAGlobalVolume: VolumeUp: -");
   140 }
   154 }
   141 
   155 
   144 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   145 //
   159 //
   146 void CMMAGlobalVolume::VolumeDown()
   160 void CMMAGlobalVolume::VolumeDown()
   147 {
   161 {
   148     DEBUG_INT("THREADID = %d : CMMAGlobalVolume: VolumeDown: +", RThread().Id());
   162     DEBUG_INT("THREADID = %d : CMMAGlobalVolume: VolumeDown: +", RThread().Id());
       
   163     DEBUG_INT("CMMAGlobalVolume: VolumeDown : iLevel = %d", iLevel);
   149     // Adjust volume if midlet is in foreground and the volume value
   164     // Adjust volume if midlet is in foreground and the volume value
   150     // is not too low, in this case it cannot be set under zero
   165     // is not too low, in this case it cannot be set under zero
   151     if (iForeground->IsForeground() && (iLevel > 0))
   166     if (iForeground->IsForeground() && (iLevel > 0))
   152     {
   167     {
   153         DEBUG("CMMAGlobalVolume: VolumeDown: Volume down");
   168         DEBUG("CMMAGlobalVolume: VolumeDown: Volume down");
   154         // Check that the currnet volume level is not decreased too much
   169         // Check that the currnet volume level is not decreased too much
   155         TInt level =
   170         TInt level =
   156             iLevel < KMMAVolumeLevelStep ?
   171             iLevel < KMMAVolumeLevelStep ?
   157             0 : iLevel - KMMAVolumeLevelStep;
   172             0 : iLevel - KMMAVolumeLevelStep;
       
   173         DEBUG_INT("CMMAGlobalVolume: VolumeDown : effective volume to be set to player = %d", level);
   158         // Decrease level by new value
   174         // Decrease level by new value
   159         SetControlVolumeLevels(level);
   175         SetControlVolumeLevels(level);
   160     }
   176     }
   161     DEBUG("CMMAGlobalVolume: VolumeDown: -");
   177     DEBUG("CMMAGlobalVolume: VolumeDown: -");
   162 }
   178 }
   186 // ---------------------------------------------------------------------------
   202 // ---------------------------------------------------------------------------
   187 //
   203 //
   188 void CMMAGlobalVolume::SetControlVolumeLevels(TInt aLevel)
   204 void CMMAGlobalVolume::SetControlVolumeLevels(TInt aLevel)
   189 {
   205 {
   190     TInt count(iControlList.Count());
   206     TInt count(iControlList.Count());
       
   207     DEBUG_INT("CMMAGlobalVolume: SetControlVolumeLevels + count of controls = %d",count);
   191     // Adjust volume for all current volume controls associated
   208     // Adjust volume for all current volume controls associated
   192     for (TInt i(0); i < count; i++)
   209     for (TInt i(0); i < count; i++)
   193     {
   210     {
   194         const TMMAPlayerHolder& hdr = iControlList[ i ];
   211         const TMMAPlayerHolder& hdr = iControlList[ i ];
   195         // Set new volume level for this control
   212         // Set new volume level for this control
   196         TRAPD(error,
   213         TRAPD(error,
   197               hdr.iVolumeControl->SetVolumeLevelL(hdr.iVolumeIndex, aLevel));
   214               hdr.iVolumeControl->SetVolumeLevelL(hdr.iVolumeIndex, aLevel));
       
   215         DEBUG_INT2("CMMAGlobalVolume: SetControlVolumeLevels level set to control = %d,err = %d",aLevel,error);
   198         if (error != KErrNone)
   216         if (error != KErrNone)
   199         {
   217         {
   200             hdr.iPlayer->PostStringEvent(
   218             hdr.iPlayer->PostStringEvent(
   201                 CMMAPlayerEvent::EError,
   219                 CMMAPlayerEvent::EError,
   202                 KMMAGlobalVolumeSetError());
   220                 KMMAGlobalVolumeSetError());
   209 
   227 
   210     // Store new volume to MMA global settings. Error cannot be reported
   228     // Store new volume to MMA global settings. Error cannot be reported
   211     // in any sophisticated way so we just have to ignore it. Debug builds
   229     // in any sophisticated way so we just have to ignore it. Debug builds
   212     // may panic in this case
   230     // may panic in this case
   213     TInt error = iSettingsStore->Set(KMobileMediaVolumeLevel, aLevel);
   231     TInt error = iSettingsStore->Set(KMobileMediaVolumeLevel, aLevel);
       
   232     DEBUG_INT2("CMMAGlobalVolume::setting the new value to Settings store, value = %d, err = %d", aLevel, error);
   214     __ASSERT_DEBUG(error == KErrNone, User::Invariant());
   233     __ASSERT_DEBUG(error == KErrNone, User::Invariant());
   215 }
   234 }
   216 
   235 
   217 // ---------------------------------------------------------------------------
   236 // ---------------------------------------------------------------------------
   218 // CMMAGlobalVolume::CMMAGlobalVolume
   237 // CMMAGlobalVolume::CMMAGlobalVolume
   233     iVolumeKeysListener = CMMAVolumeKeysListener::NewL(this);
   252     iVolumeKeysListener = CMMAVolumeKeysListener::NewL(this);
   234     iSettingsStore = CRepository::NewL(KCRUidMobileMedia);
   253     iSettingsStore = CRepository::NewL(KCRUidMobileMedia);
   235 
   254 
   236     // Get level from the settings store
   255     // Get level from the settings store
   237     User::LeaveIfError(iSettingsStore->Get(KMobileMediaVolumeLevel, iLevel));
   256     User::LeaveIfError(iSettingsStore->Get(KMobileMediaVolumeLevel, iLevel));
       
   257     DEBUG_INT("CMMAGlobalVolume::ConstructL - iLevel got from cenrep = %d", iLevel);
   238 }
   258 }
   239 
   259 
   240 // End of file
   260 // End of file