mpxmusicplayer/mediakeyhandler/src/mpxmediakeyhandlerimp.cpp
branchRCL_3
changeset 50 26a1709b9fec
parent 40 cb96c29156b2
equal deleted inserted replaced
49:455f89b7fcc5 50:26a1709b9fec
    67 const TInt KMPXMaxVolume(100);		// Max volume used in volume popup
    67 const TInt KMPXMaxVolume(100);		// Max volume used in volume popup
    68 const TInt KMPXVolumeSteps(1);
    68 const TInt KMPXVolumeSteps(1);
    69 const TInt KTenStepsVolume = 10;   
    69 const TInt KTenStepsVolume = 10;   
    70 const TInt KTwentyStepsVolume = 20;
    70 const TInt KTwentyStepsVolume = 20;
    71 const TInt KVolumePopupSynchInterval = 300000; // 300 ms
    71 const TInt KVolumePopupSynchInterval = 300000; // 300 ms
       
    72 const TInt KFilterEventInterval( 6000 ); //6ms
    72 const TRemConCoreApiOperationId KSupportedCoreFeatures[] = {
    73 const TRemConCoreApiOperationId KSupportedCoreFeatures[] = {
    73         ERemConCoreApiVolumeUp,
    74         ERemConCoreApiVolumeUp,
    74         ERemConCoreApiVolumeDown,
    75         ERemConCoreApiVolumeDown,
    75         ERemConCoreApiPlay,
    76         ERemConCoreApiPlay,
    76         ERemConCoreApiStop,
    77         ERemConCoreApiStop,
    95 CMPXMediaKeyHandlerImp::CMPXMediaKeyHandlerImp(
    96 CMPXMediaKeyHandlerImp::CMPXMediaKeyHandlerImp(
    96     MMPXMediaKeyHandlerObserver* aObserver ) :
    97     MMPXMediaKeyHandlerObserver* aObserver ) :
    97     iObserver( aObserver ),
    98     iObserver( aObserver ),
    98     iEnable( ETrue ),
    99     iEnable( ETrue ),
    99     iCurrentVol( KErrNotFound ),
   100     iCurrentVol( KErrNotFound ),
   100     iVolumeSteps(KMPXMaxVolume)
   101     iVolumeSteps(KMPXMaxVolume),
       
   102     iPreviousVol( KErrNotFound )
   101     {
   103     {
   102     }
   104     }
   103 
   105 
   104 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   105 // Symbian 2nd phase constructor can leave.
   107 // Symbian 2nd phase constructor can leave.
   209 			iUpnpCopyCommand = NULL;
   211 			iUpnpCopyCommand = NULL;
   210             }
   212             }
   211         }
   213         }
   212 #endif
   214 #endif
   213     iVolumePopupSynchTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   215     iVolumePopupSynchTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   216     iFilterEventTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   214     }
   217     }
   215 
   218 
   216 // ---------------------------------------------------------------------------
   219 // ---------------------------------------------------------------------------
   217 // Two-phased constructor.
   220 // Two-phased constructor.
   218 // ---------------------------------------------------------------------------
   221 // ---------------------------------------------------------------------------
   234 // Destructor
   237 // Destructor
   235 // ---------------------------------------------------------------------------
   238 // ---------------------------------------------------------------------------
   236 //
   239 //
   237 CMPXMediaKeyHandlerImp::~CMPXMediaKeyHandlerImp()
   240 CMPXMediaKeyHandlerImp::~CMPXMediaKeyHandlerImp()
   238     {
   241     {
       
   242 	if ( iFilterEventTimer )
       
   243 		{
       
   244 	    iFilterEventTimer->Cancel();
       
   245         delete iFilterEventTimer;
       
   246 		}
   239     if ( iVolumePopupSynchTimer )
   247     if ( iVolumePopupSynchTimer )
   240         {
   248         {
   241         iVolumePopupSynchTimer->Cancel();
   249         iVolumePopupSynchTimer->Cancel();
   242         delete iVolumePopupSynchTimer;
   250         delete iVolumePopupSynchTimer;
   243         }
   251         }
   344             	                    + iCurrentVol * KPbPlaybackVolumeLevelMax / iVolumeSteps;
   352             	                    + iCurrentVol * KPbPlaybackVolumeLevelMax / iVolumeSteps;
   345         	    }
   353         	    }
   346         	else
   354         	else
   347         	    {
   355         	    {
   348         	    volume = iCurrentVol * KPbPlaybackVolumeLevelMax/iVolumeSteps;
   356         	    volume = iCurrentVol * KPbPlaybackVolumeLevelMax/iVolumeSteps;
       
   357                 iPreviousVol = iCurrentVol;
   349         	    }
   358         	    }
   350             
   359             
   351             if ( volume < KMPXMinVolume )
   360             if ( volume < KMPXMinVolume )
   352                 {
   361                 {
   353                 volume = KMPXMinVolume;
   362                 volume = KMPXMinVolume;
   484                     if ( aValue > iVolumeSteps )
   493                     if ( aValue > iVolumeSteps )
   485                         {
   494                         {
   486                         aValue = iVolumeSteps;
   495                         aValue = iVolumeSteps;
   487                         }
   496                         }
   488                     }
   497                     }
   489 
   498                 
       
   499                 //if aValue equal to iPreviousVol, MediaKey should not set Volume again.
       
   500                 TBool OkToSetVolume = ( aValue != iPreviousVol );
       
   501                 iPreviousVol = KErrNotFound;
       
   502                 
   490                 if( iMuted && aValue > 0  ) // unmute
   503                 if( iMuted && aValue > 0  ) // unmute
   491                     {
   504                     {
   492                     iMuted = EFalse;
   505                     iMuted = EFalse;
   493                     iCurrentVol = aValue;
   506                     iCurrentVol = aValue;
   494                     }
   507                     }
   497                     if( !iMuted ) 
   510                     if( !iMuted ) 
   498                         {
   511                         {
   499                         iMuted = ETrue;
   512                         iMuted = ETrue;
   500                         }
   513                         }
   501                     }
   514                     }
   502                     else if ( aValue != iCurrentVol )
   515                 else if ( aValue != iCurrentVol )
   503                     {
   516                     {
   504                     if ( aValue != 0 && ( iResponseHandler->iCountOfVolumeCommands == 0 ) )
   517                     if ( aValue != 0 && OkToSetVolume && ( iResponseHandler->iCountOfVolumeCommands == 0 ) )
   505                         {
   518                         {
   506                         // if we are processing remcon events we shouldn't change the current volume value
   519                         // if we are processing remcon events we shouldn't change the current volume value                      
   507                         iCurrentVol = aValue;
   520                         iCurrentVol = aValue;
   508                         }
   521                         }
   509                     }
   522                     }
   510                 
   523                 
   511                 if ( iCurrentVol == KErrNotFound ) // muted by some other application before launching Music Player
   524                 if ( iCurrentVol == KErrNotFound ) // muted by some other application before launching Music Player
   512                     {
   525                     {
   513                     iCurrentVol = aValue;
   526                     iCurrentVol = aValue;
   514                     }
   527                     }
   515                 
   528                 
   516                 StartVolumePopupSynchTimer();
   529                 if ( OkToSetVolume )
       
   530                 	{
       
   531                     StartVolumePopupSynchTimer();
       
   532                 	}
   517                 
   533                 
   518                 // send a command to UI to display Volume bar on device when controlling volume via UPnP  
   534                 // send a command to UI to display Volume bar on device when controlling volume via UPnP  
   519                 if ( IsUpnpVisibleL() && iPlayerState != EPbStateNotInitialised )
   535                 if ( IsUpnpVisibleL() && iPlayerState != EPbStateNotInitialised )
   520                     {
   536                     {
   521                     TFileName subPlayerName;
   537                     TFileName subPlayerName;
  1285 				FilterAndSendCommand( EPbCmdUnMuteVolume );
  1301 				FilterAndSendCommand( EPbCmdUnMuteVolume );
  1286 				}
  1302 				}
  1287 			else
  1303 			else
  1288 				{
  1304 				{
  1289 				iCurrentVol = vol;
  1305 				iCurrentVol = vol;
  1290 				FilterAndSendCommand( EPbCmdSetVolume );
  1306 				//VolPopup CallBack functon is frequently called, 
       
  1307 				//But Music Palyer deals with the event slowly
       
  1308 				//Thus VolPopup will not display smoothly.
       
  1309 				//So Music Player needs timer to filter some events. 
       
  1310 				if ( !iFilterEventTimer->IsActive() )
       
  1311 					{
       
  1312 				    iFilterEventTimer->Start( KFilterEventInterval, 
       
  1313 				    		            KFilterEventInterval, 
       
  1314 				                        TCallBack( FilterEventTimerCallback, this ) );
       
  1315 					}
  1291 				}
  1316 				}
  1292 			}
  1317 			}
  1293 		}
  1318 		}
  1294 	}
  1319 	}
  1295 
  1320 
  1371     iVolumePopupSynchTimer->Start( KVolumePopupSynchInterval,
  1396     iVolumePopupSynchTimer->Start( KVolumePopupSynchInterval,
  1372                                    KVolumePopupSynchInterval,
  1397                                    KVolumePopupSynchInterval,
  1373                                    TCallBack( VolumePopupSynchTimerCallback, this ) );
  1398                                    TCallBack( VolumePopupSynchTimerCallback, this ) );
  1374 
  1399 
  1375     }
  1400     }
       
  1401 
       
  1402 // ---------------------------------------------------------------------------
       
  1403 // CMPXMediaKeyHandlerImp::FilterEventTimerCallback
       
  1404 // ---------------------------------------------------------------------------
       
  1405 //
       
  1406 TInt CMPXMediaKeyHandlerImp::FilterEventTimerCallback( TAny* aPtr )
       
  1407 	{
       
  1408 	static_cast<CMPXMediaKeyHandlerImp*>( aPtr )->DoFilterEventTimer();
       
  1409 	return KErrNone;
       
  1410 	}
       
  1411 
       
  1412 // ---------------------------------------------------------------------------
       
  1413 // CMPXMediaKeyHandlerImp::FilterEventTimerCallback
       
  1414 // ---------------------------------------------------------------------------
       
  1415 //
       
  1416 void CMPXMediaKeyHandlerImp::DoFilterEventTimer()
       
  1417 	{
       
  1418 	MPX_FUNC("CMPXMediaKeyHandlerImp::DoFilterEventTimer");
       
  1419 	iFilterEventTimer->Cancel();
       
  1420 	FilterAndSendCommand( EPbCmdSetVolume );
       
  1421 	}
  1376 // End of File
  1422 // End of File