mpxmusicplayer/mediakeyhandler/src/mpxmediakeyhandlerimp.cpp
branchRCL_3
changeset 28 56b11cf8addb
parent 26 70a8526f03f2
child 40 cb96c29156b2
equal deleted inserted replaced
26:70a8526f03f2 28:56b11cf8addb
    66 const TInt KMPXMinVolume(0);
    66 const TInt KMPXMinVolume(0);
    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 
    71 const TInt KVolumePopupSynchInterval = 300000; // 300 ms
    72 const TRemConCoreApiOperationId KSupportedCoreFeatures[] = {
    72 const TRemConCoreApiOperationId KSupportedCoreFeatures[] = {
    73         ERemConCoreApiVolumeUp,
    73         ERemConCoreApiVolumeUp,
    74         ERemConCoreApiVolumeDown,
    74         ERemConCoreApiVolumeDown,
    75         ERemConCoreApiPlay,
    75         ERemConCoreApiPlay,
    76         ERemConCoreApiStop,
    76         ERemConCoreApiStop,
   162         // Popup volume control
   162         // Popup volume control
   163         iVolPopup = CAknVolumePopup::NewL(NULL, ETrue);
   163         iVolPopup = CAknVolumePopup::NewL(NULL, ETrue);
   164         iVolPopup->SetObserver(this);
   164         iVolPopup->SetObserver(this);
   165         iVolPopup->SetRange(KMPXMinVolume, iVolumeSteps);
   165         iVolPopup->SetRange(KMPXMinVolume, iVolumeSteps);
   166         iVolPopup->SetStepSize(KMPXVolumeSteps);
   166         iVolPopup->SetStepSize(KMPXVolumeSteps);
   167 
   167         // Ensure that initial value is set to popup. If not initialized, CAknVolumePopup::Value() returns 0 
       
   168         // but the control appears unmuted and allows volume to be decreased out of range (panics also with Avkon 6 in UDEB)
       
   169         iVolPopup->SetValue( 0 );
       
   170         
   168         HBufC* popupText = StringLoader::LoadLC( R_MPX_VOLUME_POPUP_TEXT );
   171         HBufC* popupText = StringLoader::LoadLC( R_MPX_VOLUME_POPUP_TEXT );
   169         iVolPopup->SetTitleTextL( *popupText );
   172         iVolPopup->SetTitleTextL( *popupText );
   170         CleanupStack::PopAndDestroy( popupText );
   173         CleanupStack::PopAndDestroy( popupText );
   171         }
   174         }
   172 
   175 
   205             iUpnpFrameworkSupport = EFalse;
   208             iUpnpFrameworkSupport = EFalse;
   206 			iUpnpCopyCommand = NULL;
   209 			iUpnpCopyCommand = NULL;
   207             }
   210             }
   208         }
   211         }
   209 #endif
   212 #endif
       
   213     iVolumePopupSynchTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   210     }
   214     }
   211 
   215 
   212 // ---------------------------------------------------------------------------
   216 // ---------------------------------------------------------------------------
   213 // Two-phased constructor.
   217 // Two-phased constructor.
   214 // ---------------------------------------------------------------------------
   218 // ---------------------------------------------------------------------------
   230 // Destructor
   234 // Destructor
   231 // ---------------------------------------------------------------------------
   235 // ---------------------------------------------------------------------------
   232 //
   236 //
   233 CMPXMediaKeyHandlerImp::~CMPXMediaKeyHandlerImp()
   237 CMPXMediaKeyHandlerImp::~CMPXMediaKeyHandlerImp()
   234     {
   238     {
       
   239     if ( iVolumePopupSynchTimer )
       
   240         {
       
   241         iVolumePopupSynchTimer->Cancel();
       
   242         delete iVolumePopupSynchTimer;
       
   243         }
   235     if ( iPlaybackUtility )
   244     if ( iPlaybackUtility )
   236         {
   245         {
   237         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
   246         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
   238         iPlaybackUtility->Close();
   247         iPlaybackUtility->Close();
   239         }
   248         }
   322                 }
   331                 }
   323             }
   332             }
   324 
   333 
   325         if ( forwardCommand )
   334         if ( forwardCommand )
   326             {
   335             {
   327             iVolumeEventCount++;
       
   328         	
       
   329             TInt volume(0);
   336             TInt volume(0);
   330             TFileName subPlayerName;
   337             TFileName subPlayerName;
   331             TMPXPlaybackPlayerType currentPlayerType = EPbLocal;
   338             TMPXPlaybackPlayerType currentPlayerType = EPbLocal;
   332             GetSubPlayerInfoL(subPlayerName, currentPlayerType);
   339             GetSubPlayerInfoL(subPlayerName, currentPlayerType);
   333             
   340             
   348             if ( volume > KMPXMaxVolume )
   355             if ( volume > KMPXMaxVolume )
   349                 {
   356                 {
   350                 volume = KMPXMaxVolume;
   357                 volume = KMPXMaxVolume;
   351                 }
   358                 }
   352             
   359             
       
   360             MPX_DEBUG3( "CMPXMediaKeyHandlerImp::DoFilterAndSendCommandL: aCommandId(%d), volume(%d)" , aCommandId, volume );
   353             iObserver->HandleMediaKeyCommand( aCommandId, volume );
   361             iObserver->HandleMediaKeyCommand( aCommandId, volume );
   354             }
   362             }
   355         }
   363         }
   356     }
   364     }
   357 
   365 
   459                 ShowPlaybackPopupL( EMPXPopupShowIfVisible );
   467                 ShowPlaybackPopupL( EMPXPopupShowIfVisible );
   460                 break;
   468                 break;
   461                 }
   469                 }
   462             case EPbPropertyMute:
   470             case EPbPropertyMute:
   463             	{
   471             	{
   464                 if ( iTouchVolEventCount > 0 )
       
   465                     {
       
   466                     --iTouchVolEventCount;
       
   467                     }
       
   468                 if ( iVolumeEventCount > 0 )
       
   469                 	{
       
   470                 	--iVolumeEventCount;
       
   471                 	}
       
   472             	iMuted = aValue;
   472             	iMuted = aValue;
   473             	if ( iMuted )
   473             	StartVolumePopupSynchTimer();
   474             	    {
       
   475             	    iVolPopup->SetValue( 0 );
       
   476             	    }
       
   477             	else
       
   478             		{
       
   479             		iVolPopup->SetValue( iCurrentVol );
       
   480             		}
       
   481 				break;
   474 				break;
   482 				}
   475 				}
   483 			case EPbPropertyVolume:
   476 			case EPbPropertyVolume:
   484                 {
   477                 {
   485 				if ( iVolPopup )
   478                 // Avkon Volume has 10 steps, but the rest of the framework
   486 					{
   479                 // has 100 steps. Need to scale it to 10 steps.
   487 	                if ( iTouchVolEventCount > 0 )
   480                 if ( aValue > 0 )
   488 	                    {
   481                     {
   489 	                    --iTouchVolEventCount;
   482                     aValue = aValue * iVolumeSteps;
   490 	                    }
   483                     aValue = aValue / KPbPlaybackVolumeLevelMax;
   491 					// Avkon Volume has 10 steps, but the rest of the framework
   484                     if ( aValue > iVolumeSteps )
   492                     // has 100 steps. Need to scale it to 10 steps.
       
   493                     if ( aValue > 0 )
       
   494                         {
   485                         {
   495                         aValue = aValue * iVolumeSteps;
   486                         aValue = iVolumeSteps;
   496                         aValue = aValue / KPbPlaybackVolumeLevelMax;
       
   497                         if ( aValue > iVolumeSteps )
       
   498                         	{
       
   499                         	aValue = iVolumeSteps;
       
   500                         	}
       
   501                         }
   487                         }
   502 
   488                     }
   503 					if( !iMuted && aValue > 0 ) // unmute
   489 
   504 			            {
   490                 if( iMuted && aValue > 0  ) // unmute
   505 			            iMuted = EFalse;
   491                     {
   506 			            iCurrentVol = aValue;
   492                     iMuted = EFalse;
   507 			            iVolPopup->SetValue( iCurrentVol );
   493                     iCurrentVol = aValue;
   508 			            }
   494                     }
   509 		            else if( aValue == 0 ) // mute
   495                 else if( aValue == 0 ) // mute
   510 			            {
   496                     {
   511 			            if( !iMuted ) 
   497                     if( !iMuted ) 
   512 				            {
       
   513 				            iMuted = ETrue;
       
   514 				            iVolPopup->SetValue( 0 );
       
   515 				            }
       
   516 			            }
       
   517                     else if ( aValue != iCurrentVol && !iTouchVolEventCount && !iVolumeEventCount )
       
   518 					    {
       
   519 					    if ( aValue != 0 )
       
   520 					        {
       
   521 					        iCurrentVol = aValue;
       
   522 					        }
       
   523 				        iVolPopup->SetValue( iCurrentVol );
       
   524 					    }
       
   525 
       
   526 				    if ( iVolumeEventCount > 0 )
       
   527 				    	{
       
   528 				    	--iVolumeEventCount;
       
   529 					    }
       
   530 
       
   531                     // send a command to UI to display Volume bar on device when controlling volume via UPnP  
       
   532                     if ( IsUpnpVisibleL() && iPlayerState != EPbStateNotInitialised )
       
   533                         {
   498                         {
   534                         TFileName subPlayerName;
   499                         iMuted = ETrue;
   535                         TMPXPlaybackPlayerType currentPlayerType = EPbLocal;
       
   536                         GetSubPlayerInfoL( subPlayerName, currentPlayerType );
       
   537 
       
   538                         if ( currentPlayerType != EPbLocal )
       
   539                             {
       
   540                             iObserver->HandleMediaKeyCommand( EPbCmdSetVolume, iUpnpVolume ); 
       
   541                             }            
       
   542                         }
   500                         }
   543 							  
   501                     }
   544 					if ( iUpnpFrameworkSupport )
   502                     else if ( aValue != iCurrentVol )
   545 						{
   503                     {
   546 						SetVolumePopupTitleL();
   504                     if ( aValue != 0 )
   547 						}
   505                         {
   548 					}
   506                         iCurrentVol = aValue;
       
   507                         }
       
   508                     }
       
   509                 
       
   510                 if ( iCurrentVol == KErrNotFound ) // muted by some other application before launching Music Player
       
   511                     {
       
   512                     iCurrentVol = aValue;
       
   513                     }
       
   514                 
       
   515                 StartVolumePopupSynchTimer();
       
   516                 
       
   517                 // send a command to UI to display Volume bar on device when controlling volume via UPnP  
       
   518                 if ( IsUpnpVisibleL() && iPlayerState != EPbStateNotInitialised )
       
   519                     {
       
   520                     TFileName subPlayerName;
       
   521                     TMPXPlaybackPlayerType currentPlayerType = EPbLocal;
       
   522                     GetSubPlayerInfoL( subPlayerName, currentPlayerType );
       
   523 
       
   524                     if ( currentPlayerType != EPbLocal )
       
   525                         {
       
   526                         iObserver->HandleMediaKeyCommand( EPbCmdSetVolume, iUpnpVolume ); 
       
   527                         }            
       
   528                     }
       
   529                           
       
   530                 if ( iUpnpFrameworkSupport )
       
   531                     {
       
   532                     SetVolumePopupTitleL();
       
   533                     }
       
   534 					
   549 				break;
   535 				break;
   550                 }
   536                 }
   551             default:
   537             default:
   552                 {
   538                 {
   553                 break;
   539                 break;
   769 		{
   755 		{
   770 		if ( iMuted )
   756 		if ( iMuted )
   771 			{
   757 			{
   772 			iMuted = EFalse;
   758 			iMuted = EFalse;
   773 			iCommandId = EPbCmdUnMuteVolume;
   759 			iCommandId = EPbCmdUnMuteVolume;
       
   760             if ( iCurrentVol == 0 ) // prevent muting again when HandleControlEvent is called next time
       
   761                 {
       
   762                 iCurrentVol = 1; // "1" is the first step of 20-step volume
       
   763                 }
   774 			iVolPopup->SetValue( iCurrentVol );
   764 			iVolPopup->SetValue( iCurrentVol );
   775 			}
   765 			}
   776 		else
   766 		else
   777 			{
   767 			{
   778 			iCommandId = EPbCmdSetVolume;
   768 			iCommandId = EPbCmdSetVolume;
   779 			iCurrentVol = iCurrentVol < iVolumeSteps ? (iCurrentVol + 1) : iCurrentVol;	// +KMPXVolumeSteps; ?
   769 			iCurrentVol = iCurrentVol < iVolumeSteps ? (iCurrentVol + 1) : iCurrentVol;
   780 			iVolPopup->SetValue( iCurrentVol );
   770 			iVolPopup->SetValue( iCurrentVol );
   781 			}
   771 			}
   782 		}
   772 		}
   783 	else
   773 	else
   784 		{
   774 		{
   795 			iVolPopup->SetValue( iCurrentVol );
   785 			iVolPopup->SetValue( iCurrentVol );
   796 			}
   786 			}
   797 		else
   787 		else
   798 			{
   788 			{
   799 			iCommandId = EPbCmdSetVolume;
   789 			iCommandId = EPbCmdSetVolume;
   800 			iCurrentVol = iCurrentVol - 1;	// KMPXVolumeSteps ?
   790 			iCurrentVol = iCurrentVol - 1;
   801 			iVolPopup->SetValue( iCurrentVol );
   791 			iVolPopup->SetValue( iCurrentVol );
   802 			}
   792 			}
   803 		}
   793 		}
   804 	}
   794 	}
   805 
   795 
  1239 // void CMPlayerBaseView::HandleControlEventL
  1229 // void CMPlayerBaseView::HandleControlEventL
  1240 // ----------------------------------------------------------------------------
  1230 // ----------------------------------------------------------------------------
  1241 //
  1231 //
  1242 void CMPXMediaKeyHandlerImp::HandleControlEventL( CCoeControl* aControl, TCoeEvent aEventType )
  1232 void CMPXMediaKeyHandlerImp::HandleControlEventL( CCoeControl* aControl, TCoeEvent aEventType )
  1243 	{
  1233 	{
       
  1234     MPX_FUNC("CMPXMediaKeyHandlerImp::HandleControlEventL");
  1244 	if ( !AknLayoutUtils::PenEnabled() )
  1235 	if ( !AknLayoutUtils::PenEnabled() )
  1245 		{
  1236 		{
  1246 		return;
  1237 		return;
  1247 		}
  1238 		}
  1248 
  1239 
  1249 	if( (aEventType == EEventStateChanged) && (aControl == iVolPopup) )
  1240 	if( (aEventType == EEventStateChanged) && (aControl == iVolPopup) )
  1250 		{
  1241 		{
  1251 		TInt vol = iVolPopup->Value();
  1242 		TInt vol = iVolPopup->Value();
  1252 		if ( vol == iCurrentVol )
  1243 		
       
  1244 		MPX_DEBUG4( "CMPXMediaKeyHandlerImp::HandleControlEventL: vol(%d), iCurrentVol(%d), iMuted(%d)", vol, iCurrentVol, iMuted );
       
  1245 		
       
  1246 		if ( vol == iCurrentVol && vol != 0 )
  1253 		    {
  1247 		    {
  1254             if ( iMuted )
  1248             if ( iMuted )
  1255                 {
  1249                 {
  1256                 iMuted = EFalse;
  1250                 iMuted = EFalse;
  1257                 FilterAndSendCommand( EPbCmdUnMuteVolume );
  1251                 FilterAndSendCommand( EPbCmdUnMuteVolume );
  1258                 iTouchVolEventCount++;
       
  1259                 }
  1252                 }
  1260             else
  1253             else
  1261                 {
  1254                 {
  1262                 return;
  1255                 return;
  1263                 }
  1256                 }
  1271 			    }
  1264 			    }
  1272 			else
  1265 			else
  1273 			    {
  1266 			    {
  1274 			    iMuted = ETrue;
  1267 			    iMuted = ETrue;
  1275 			    FilterAndSendCommand( EPbCmdMuteVolume );
  1268 			    FilterAndSendCommand( EPbCmdMuteVolume );
  1276 			    iTouchVolEventCount++;
       
  1277 			    }
  1269 			    }
  1278 			}
  1270 			}
  1279 		else
  1271 		else
  1280 			{
  1272 			{
  1281 			if ( iMuted )
  1273 			if ( iMuted )
  1282 				{
  1274 				{
  1283 				iMuted = EFalse;
  1275 				iMuted = EFalse;
       
  1276 				
       
  1277 				if ( iCurrentVol == 0 ) // setting volume to 0 would reapply mute, use slider value instead
       
  1278 				    {
       
  1279                     iCurrentVol = vol;
       
  1280 				    }
       
  1281 				
  1284 				iVolPopup->SetValue( iCurrentVol );
  1282 				iVolPopup->SetValue( iCurrentVol );
  1285 				FilterAndSendCommand( EPbCmdUnMuteVolume );
  1283 				FilterAndSendCommand( EPbCmdUnMuteVolume );
  1286 				iTouchVolEventCount++;
       
  1287 				}
  1284 				}
  1288 			else
  1285 			else
  1289 				{
  1286 				{
  1290 				iCurrentVol = vol;
  1287 				iCurrentVol = vol;
  1291 				FilterAndSendCommand( EPbCmdSetVolume );
  1288 				FilterAndSendCommand( EPbCmdSetVolume );
  1292 				iTouchVolEventCount++;
       
  1293 				}
  1289 				}
  1294 			}
  1290 			}
  1295 		}
  1291 		}
  1296 	}
  1292 	}
  1297 
  1293 
  1317             } );
  1313             } );
  1318         }
  1314         }
  1319 
  1315 
  1320     return isForeground;
  1316     return isForeground;
  1321     }
  1317     }
       
  1318 
       
  1319 // ---------------------------------------------------------------------------
       
  1320 // CMPXMediaKeyHandlerImp::VolumePopupSynchTimerCallback
       
  1321 // ---------------------------------------------------------------------------
       
  1322 //
       
  1323 TInt CMPXMediaKeyHandlerImp::VolumePopupSynchTimerCallback( TAny* aPtr )
       
  1324     {
       
  1325     static_cast<CMPXMediaKeyHandlerImp*>( aPtr )->DoVolumePopupSynch();
       
  1326     return KErrNone;
       
  1327     }
       
  1328 
       
  1329 // ---------------------------------------------------------------------------
       
  1330 // CMPXMediaKeyHandlerImp::DoVolumePopupSynch
       
  1331 // ---------------------------------------------------------------------------
       
  1332 //
       
  1333 void CMPXMediaKeyHandlerImp::DoVolumePopupSynch()
       
  1334     {
       
  1335     MPX_FUNC("CMPXMediaKeyHandlerImp::DoVolumePopupSynch");
       
  1336     
       
  1337     iVolumePopupSynchTimer->Cancel();
       
  1338     
       
  1339     TInt popupValue = iVolPopup->Value();
       
  1340     
       
  1341     MPX_DEBUG4("CMPXMediaKeyHandlerImp::DoVolumePopupSynch: popupValue(%d), iMuted(%d), iCurrentVol(%d)",
       
  1342                popupValue, iMuted, iCurrentVol );
       
  1343     
       
  1344     if ( iMuted )
       
  1345         {
       
  1346         if ( popupValue != 0 )
       
  1347             {
       
  1348             MPX_DEBUG1("CMPXMediaKeyHandlerImp::DoVolumePopupSynch: popup out of synch (muted)" );
       
  1349             iVolPopup->SetValue( 0 );
       
  1350             }
       
  1351         }
       
  1352     else
       
  1353         {
       
  1354         if ( iCurrentVol != popupValue )
       
  1355             {
       
  1356             MPX_DEBUG1("CMPXMediaKeyHandlerImp::DoVolumePopupSynch: popup out of synch" );
       
  1357             iVolPopup->SetValue( iCurrentVol );
       
  1358             }
       
  1359         }
       
  1360     }
       
  1361 
       
  1362 // ---------------------------------------------------------------------------
       
  1363 // CMPXMediaKeyHandlerImp::StartVolumePopupSynchTimer
       
  1364 // ---------------------------------------------------------------------------
       
  1365 //
       
  1366 void CMPXMediaKeyHandlerImp::StartVolumePopupSynchTimer()
       
  1367     {
       
  1368     iVolumePopupSynchTimer->Cancel();
       
  1369     iVolumePopupSynchTimer->Start( KVolumePopupSynchInterval,
       
  1370                                    KVolumePopupSynchInterval,
       
  1371                                    TCallBack( VolumePopupSynchTimerCallback, this ) );
       
  1372 
       
  1373     }
  1322 // End of File
  1374 // End of File