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 |
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 } |
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 { |
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 } |
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 |