mpxplugins/serviceplugins/playbackplugins/localaudio/src/mpxlocalaudioplayback.cpp
branchRCL_3
changeset 53 3de6c4cf6b67
equal deleted inserted replaced
52:14979e23cb5e 53:3de6c4cf6b67
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class plays local audio file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 //<branchInfo originator="alakurik" since="26-NOV-2007"/>
       
    21 // Including adaptationaudiopreference.h instead of audiopreference.h to
       
    22 // bring in needed constants for __HIGH_RESOLUTION_VOLUME
       
    23 //</branchInfo>
       
    24 //BRANCH 26-NOV-2007
       
    25 //#include <audiopreference.h>
       
    26 //BRANCH_END
       
    27 #if defined(__HIGH_RESOLUTION_VOLUME) && !defined(__LOW_POWER_AUDIO_PLAYBACK)
       
    28 #include <adaptationaudiopreference.h>
       
    29 #else
       
    30 #include <AudioPreference.h>
       
    31 #endif
       
    32 #include <badesca.h>
       
    33 #include <apgcli.h>
       
    34 #include <mmf/common/mmfcontrollerframeworkbase.h>
       
    35 #include <mmf/common/mmfmeta.h>
       
    36 #include <mpxmedia.h>
       
    37 #include <mpxdrmmediautility.h>
       
    38 #include <mpxmediadrmdefs.h>
       
    39 #include <mpxplaybackpluginobserver.h>
       
    40 #include <mpxmediaaudiodefs.h>
       
    41 #include <mpxmediamusicdefs.h>
       
    42 #include <mpxmediageneraldefs.h>
       
    43 #include <mpxmediadrmdefs.h>
       
    44 #include "mpxaudioeffectengine.h"
       
    45 #include <mpxprivatecrkeys.h>
       
    46 #include <mpxcenrepwatcher.h>
       
    47 
       
    48 #include "mpxlocalaudioplayback.h"
       
    49 #include "mpxlog.h"
       
    50 
       
    51 // CONSTANTS
       
    52 const TUid  KLocalPlaybackUid={0x101FFC06};
       
    53 _LIT(KWmaExtension, ".wma");
       
    54 _LIT(KRaExtension, ".ra"); 
       
    55 
       
    56     
       
    57 // ============================ LOCAL FUNCTIONS ==============================
       
    58 LOCAL_C TInt Balance(TInt aMMFBalance)
       
    59     {
       
    60     return (aMMFBalance-KMMFBalanceCenter) *
       
    61            (EPbBalanceMaxRight-EPbBalanceMaxLeft) /
       
    62            (KMMFBalanceMaxRight-KMMFBalanceMaxLeft);
       
    63     }
       
    64 
       
    65 LOCAL_C TInt MMFBalance(TInt aBalance)
       
    66     {
       
    67     return KMMFBalanceCenter+(KMMFBalanceMaxRight-KMMFBalanceMaxLeft)/
       
    68            (EPbBalanceMaxRight-EPbBalanceMaxLeft)*aBalance;
       
    69     }
       
    70 
       
    71 
       
    72 // ============================ MEMBER FUNCTIONS ==============================
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // Two-phased constructor.
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 CMPXLocalAudioPlayback* CMPXLocalAudioPlayback::NewL(TAny* /*aInitParams*/)
       
    79     {
       
    80     CMPXLocalAudioPlayback* p=new(ELeave)CMPXLocalAudioPlayback();
       
    81     CleanupStack::PushL(p);
       
    82     p->ConstructL();
       
    83     CleanupStack::Pop(p);
       
    84     return p;
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // Symbian 2nd phase constructor can leave.
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 void CMPXLocalAudioPlayback::ConstructL()
       
    92     {
       
    93     MPX_FUNC_EX("CMPXLocalAudioPlayback::ConstructL()");
       
    94     iVolumeWatcher = CMPXCenRepWatcher::NewL(KCRUidMPXSettings,
       
    95                                              KMPXPlaybackVolume,
       
    96                                              this);
       
    97 
       
    98     iMuteWatcher = CMPXCenRepWatcher::NewL(KCRUidMPXSettings,
       
    99                                            KMPXPlaybackMute,
       
   100                                            this);
       
   101 
       
   102     iPlayer = CMdaAudioPlayerUtility::NewL(*this,
       
   103 #ifdef __LOW_POWER_AUDIO_PLAYBACK
       
   104                         KAudioPriorityMusicPlayer,
       
   105                         TMdaPriorityPreference(KAudioPrefMusicLocalPlayback));
       
   106 #else
       
   107 #ifdef __HIGH_RESOLUTION_VOLUME
       
   108                         KAudioPriorityTwentyStepsVolumeMusicPlayer,
       
   109                         TMdaPriorityPreference(KAudioPrefTwentyStepsVolumeMusicPlayerPlayback));
       
   110 #else
       
   111                         KAudioPriorityRealOnePlayer,
       
   112                         TMdaPriorityPreference(KAudioPrefRealOneLocalPlayback));
       
   113 #endif // __HIGH_RESOLUTION_VOLUME
       
   114 #endif // __LOW_POWER_AUDIO_PLAYBACK
       
   115 
       
   116     User::LeaveIfError(iFs.Connect());
       
   117     iFs.ShareProtected();
       
   118     iDrmMediaUtility = CMPXDrmMediaUtility::NewL();
       
   119     iAudioEffects = CMPXAudioEffectEngine::NewL( iPlayer );
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // C++ constructor
       
   124 // ----------------------------------------------------------------------------
       
   125 //
       
   126 CMPXLocalAudioPlayback::CMPXLocalAudioPlayback()
       
   127 	: iAudioEffectsOn(ETrue), iIsPlaying(EFalse)
       
   128     {}
       
   129 
       
   130 // ----------------------------------------------------------------------------
       
   131 // Destructor
       
   132 // ----------------------------------------------------------------------------
       
   133 //
       
   134 CMPXLocalAudioPlayback::~CMPXLocalAudioPlayback()
       
   135     {
       
   136     MPX_FUNC_EX("CMPXLocalAudioPlayback::~CMPXLocalAudioPlayback");
       
   137     delete iMuteWatcher;
       
   138     delete iVolumeWatcher;
       
   139     if ( iDrmMediaUtility )
       
   140         {
       
   141         TRAP_IGNORE( ConsumeRightsL( ContentAccess::EStop ) );
       
   142         iDrmMediaUtility->Close();
       
   143         delete iDrmMediaUtility;
       
   144         }
       
   145     if( iAudioEffects )
       
   146         {
       
   147         iAudioEffects->DestroyAudioEffect();
       
   148         delete iAudioEffects;
       
   149         }
       
   150     if (iPlayer)
       
   151         {
       
   152         iPlayer->Close();
       
   153         delete iPlayer;
       
   154         }
       
   155     iFile.Close();
       
   156     iFs.Close();
       
   157     delete iSong;
       
   158     }
       
   159 
       
   160 // ----------------------------------------------------------------------------
       
   161 // Set observer
       
   162 // ----------------------------------------------------------------------------
       
   163 //
       
   164 void CMPXLocalAudioPlayback::SetObserver(MMPXPlaybackPluginObserver& aObs)
       
   165     {
       
   166     MPX_FUNC_EX("CMPXLocalAudioPlayback::SetObserver(MMPXPlaybackPluginObserver& aObs)");
       
   167     iObs = &aObs;
       
   168     }
       
   169 
       
   170 // ----------------------------------------------------------------------------
       
   171 // Initializes a song for playback
       
   172 // ----------------------------------------------------------------------------
       
   173 //
       
   174 void CMPXLocalAudioPlayback::InitialiseL(const TDesC& aSong)
       
   175     {
       
   176     MPX_DEBUG3("-->CMPXLocalAudioPlayback::InitialiseL 0x%08x, (%S)", this, &aSong);
       
   177 
       
   178     iDrmMediaUtility->Close();
       
   179     delete iSong;
       
   180     iSong = NULL;
       
   181     iSong = aSong.AllocL();
       
   182     iFile.Close();
       
   183     TInt err( iFile.Open( iFs, aSong, EFileRead | EFileShareReadersOrWriters ));
       
   184     // Remap KErrNotReady to KErrNotFound, because it is referencing a drive
       
   185     // that is not existent
       
   186     if ( KErrNotReady == err )
       
   187         {
       
   188         err = KErrNotFound;
       
   189         }
       
   190     User::LeaveIfError( err );
       
   191     
       
   192 #if defined(__HIGH_RESOLUTION_VOLUME)
       
   193     TParsePtrC parser(aSong);
       
   194     
       
   195     // Merlin twentysteps hack start
       
   196     if (parser.Ext().CompareF(KWmaExtension) == 0 || parser.Ext().CompareF(KRaExtension) == 0)
       
   197         {
       
   198         // This is a wma song, need to delete iPlayer and reset the volume resolution
       
   199         // this is because the volume level 20 is not supported for wma with headphone
       
   200         MPX_DEBUG1("CMPXLocalAudioPlayback::InitialiseL it is a wma file, so set to 10 steps");
       
   201         delete iAudioEffects;
       
   202         iAudioEffects = NULL;
       
   203         delete iPlayer;
       
   204         iPlayer = NULL;
       
   205         iPlayer = CMdaAudioPlayerUtility::NewL(*this,
       
   206                         KAudioPriorityRealOnePlayer,
       
   207                         TMdaPriorityPreference(KAudioPrefRealOneLocalPlayback));
       
   208         // Also regenerate audio effects
       
   209         iAudioEffects = CMPXAudioEffectEngine::NewL( iPlayer );
       
   210         }                        
       
   211     // Merlin twentysteps hack end
       
   212 #endif // __HIGH_RESOLUTION_VOLUME
       
   213     TMMFileHandleSource source(iFile, KDefaultContentObject, EPlay);
       
   214     iPlayer->OpenFileL(source);
       
   215     iDrmMediaUtility->InitL( iFile );
       
   216     iState = EStateInitialising;
       
   217     iClosedByAudioPolicy = EFalse;
       
   218     iConsumeStarted = EFalse;
       
   219 
       
   220     MPX_DEBUG3("<--CMPXLocalAudioPlayback::InitialiseL 0x%08x, (%S)", this, &aSong);
       
   221     }
       
   222 
       
   223 // ----------------------------------------------------------------------------
       
   224 // Initializes a song for playback
       
   225 // ----------------------------------------------------------------------------
       
   226 //
       
   227 void CMPXLocalAudioPlayback::InitialiseL(RFile& aSong)
       
   228     {
       
   229     MPX_DEBUG2("-->CMPXLocalAudioPlayback::InitialiseL(RFile) 0x%08x", this);
       
   230 
       
   231     iDrmMediaUtility->Close();
       
   232     delete iSong;
       
   233     iSong = NULL;
       
   234     iSong = HBufC::NewL(KMaxFileName);
       
   235     TPtr ptr = iSong->Des();
       
   236     aSong.FullName(ptr);
       
   237     
       
   238 #if defined(__HIGH_RESOLUTION_VOLUME)
       
   239     TParsePtrC parser(ptr);
       
   240     
       
   241     // Merlin twentysteps hack start
       
   242     if (parser.Ext().CompareF(KWmaExtension) == 0 || parser.Ext().CompareF(KRaExtension) == 0)
       
   243         {
       
   244         // This is a wma song, need to delete iPlayer and reset the volume resolution
       
   245         // this is because the volume level 20 is not supported for wma with headphone
       
   246         delete iAudioEffects;
       
   247         iAudioEffects = NULL;
       
   248         delete iPlayer;
       
   249         iPlayer = NULL;
       
   250         iPlayer = CMdaAudioPlayerUtility::NewL(*this,
       
   251                         KAudioPriorityRealOnePlayer,
       
   252                         TMdaPriorityPreference(KAudioPrefRealOneLocalPlayback));
       
   253         // Also regenerate audio effects
       
   254         iAudioEffects = CMPXAudioEffectEngine::NewL( iPlayer );
       
   255         }    
       
   256     // Merlin twentysteps hack end
       
   257 #endif // __HIGH_RESOLUTION_VOLUME
       
   258     TMMFileHandleSource source(aSong, KDefaultContentObject, EPlay);
       
   259     iPlayer->OpenFileL(source);
       
   260     User::LeaveIfError( iFile.Duplicate( aSong ));
       
   261     iDrmMediaUtility->InitL( iFile );
       
   262     iState = EStateInitialising;
       
   263     iClosedByAudioPolicy = EFalse;
       
   264     iConsumeStarted = EFalse;
       
   265 
       
   266     MPX_DEBUG2("<--CMPXLocalAudioPlayback::InitialiseL(RFile) 0x%08x", this);
       
   267     }
       
   268 
       
   269 // ----------------------------------------------------------------------------
       
   270 // Executes a command on the selected song
       
   271 // ----------------------------------------------------------------------------
       
   272 //
       
   273 void CMPXLocalAudioPlayback::CommandL(TMPXPlaybackCommand aCmd, TInt aData)
       
   274     {
       
   275     MPX_DEBUG3("-->CMPXLocalAudioPlayback::CommandL 0x%08x cmd %d", this, aCmd);
       
   276     switch(aCmd)
       
   277         {
       
   278         case EPbCmdPlay:
       
   279             {
       
   280             // If closed by audio policy, then play command will need to
       
   281             // re-initialise the plugin first.
       
   282             if ( iClosedByAudioPolicy )
       
   283                 {
       
   284                 HBufC* song( iSong->AllocLC() );
       
   285                 InitialiseL( *song );
       
   286                 iConsumeStarted = ETrue;
       
   287                 CleanupStack::PopAndDestroy( song );
       
   288                 iClosedByAudioPolicy = EFalse;
       
   289                 }
       
   290             else
       
   291                 {
       
   292                 // Treat song as play complete if try to play at end of song
       
   293                 TTimeIntervalMicroSeconds dur( iPlayer->Duration() );
       
   294                 TTimeIntervalMicroSeconds pos( 0 );
       
   295                 TInt err( iPlayer->GetPosition( pos ));
       
   296                 MPX_DEBUG4("CMPXLocalAudioPlayback::CommandL(): dur=%d, pos=%d, err=%d", I64INT(dur.Int64()), I64INT(pos.Int64()), err);
       
   297                 if ( !err &&
       
   298                      Abs( dur.Int64() - pos.Int64() ) < KPbMilliMultiplier &&
       
   299                      dur.Int64() > KPbMilliMultiplier )
       
   300                     {
       
   301                     MapcPlayComplete( KErrNone );
       
   302                     }
       
   303                 else
       
   304                     {
       
   305                     if (iConsumeStarted)
       
   306                         {
       
   307                         TRAPD( drmErr, ConsumeRightsL( ContentAccess::EContinue ) );
       
   308                         if ( drmErr == KErrCANoRights )
       
   309                             {
       
   310                             iDrmMediaUtility->Close();
       
   311                             iPlayer->Stop();
       
   312                             iIsPlaying = EFalse;
       
   313                             iAudioEffects->DestroyAudioEffect();
       
   314                             iPlayer->Close();
       
   315                             iObs->HandlePluginEvent(
       
   316                                     MMPXPlaybackPluginObserver::EPStopped, 0,
       
   317                                     drmErr);
       
   318                             iFile.Close();
       
   319                             iState = EStateNotInitialised;
       
   320                             iObs->HandlePluginEvent(
       
   321                                     MMPXPlaybackPluginObserver::EPClosed,
       
   322                                     EPbCmdStop, drmErr);
       
   323                             iClosedByAudioPolicy = EFalse;
       
   324                             break;
       
   325                             }
       
   326                         }
       
   327                     else
       
   328                         {
       
   329                         MPX_TRAPD( AEErr,  ConsumeRightsL( ContentAccess::EPlay ) );
       
   330                         iState = EStateInitialised;
       
   331                         if (AEErr == KErrDiskFull)
       
   332                         	{
       
   333                         	iDrmMediaUtility->Close();
       
   334 				            iPlayer->Stop();
       
   335 				            iIsPlaying = EFalse;
       
   336 				            iAudioEffects->DestroyAudioEffect();
       
   337 				            iPlayer->Close();
       
   338 				            iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPStopped,
       
   339 				                    0, KErrDiskFull);
       
   340 				            iFile.Close();
       
   341 				            iState = EStateNotInitialised;
       
   342 				            iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPClosed,
       
   343 				                                    EPbCmdStop, KErrDiskFull);
       
   344 				            iClosedByAudioPolicy = EFalse;
       
   345 				            break;
       
   346                         	}
       
   347                         iConsumeStarted = ETrue;
       
   348                         }
       
   349 
       
   350 					if ( iAudioEffectsOn )
       
   351 						{
       
   352                     	MPX_TRAP( err,  iAudioEffects->CreateAudioEffectsL() );
       
   353 						}
       
   354 
       
   355                     iPlayer->Play();
       
   356                     iIsPlaying = ETrue;
       
   357 
       
   358                     if( iAudioEffectsOn && err != KErrNone )
       
   359                         {
       
   360                         MPX_TRAP( err,  iAudioEffects->CreateAudioEffectsL() );
       
   361                         }
       
   362 
       
   363                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPlaying,
       
   364                                              0, KErrNone);
       
   365                     }
       
   366                 }
       
   367             break;
       
   368             }
       
   369         case EPbCmdPause:
       
   370             {
       
   371             TRAP_IGNORE( ConsumeRightsL( ContentAccess::EPause ) );
       
   372 
       
   373             TInt err( iPlayer->Pause() );
       
   374             iIsPlaying = EFalse;
       
   375             iAudioEffects->DestroyAudioEffect();
       
   376 
       
   377             MPX_DEBUG2("CMPXLocalAudioPlayback::CommandL(): Pause err = %d", err);
       
   378             // If pause is not supported, resend the play command so plugin
       
   379             // state is correct.
       
   380             // This is for cases like playing .RNG files
       
   381             if ( KErrNotSupported == err )
       
   382                 {
       
   383                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPaused,
       
   384                                          0,
       
   385                                          KErrNone);
       
   386                 iPlayer->Play();
       
   387                 iIsPlaying = ETrue;
       
   388                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlaying,
       
   389                                          0,
       
   390                                          KErrNone);
       
   391                 }
       
   392             else
       
   393                 {
       
   394                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPaused,
       
   395                                          0,
       
   396                                          err);
       
   397                 }
       
   398             iClosedByAudioPolicy = EFalse;
       
   399             break;
       
   400             }
       
   401         case EPbCmdStop:
       
   402             {
       
   403             TRAP_IGNORE( ConsumeRightsL( ContentAccess::EStop ));
       
   404             iConsumeStarted = EFalse;
       
   405             iDrmMediaUtility->Close();
       
   406             iPlayer->Stop();
       
   407             iIsPlaying = EFalse;
       
   408             iAudioEffects->DestroyAudioEffect();
       
   409             iPlayer->Close();
       
   410 
       
   411             iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPStopped,
       
   412                     0, KErrNone);
       
   413             iFile.Close();
       
   414             iState = EStateNotInitialised;
       
   415             iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPClosed,
       
   416                                     EPbCmdStop, KErrNone);
       
   417             iClosedByAudioPolicy = EFalse;
       
   418             break;
       
   419             }
       
   420         case EPbCmdClose:
       
   421             {
       
   422             TRAP_IGNORE( ConsumeRightsL( ContentAccess::EStop ));
       
   423             iConsumeStarted = EFalse;
       
   424             iDrmMediaUtility->Close();
       
   425             iAudioEffects->DestroyAudioEffect();
       
   426             iPlayer->Close();
       
   427             iIsPlaying = EFalse;
       
   428             iFile.Close();
       
   429             iState = EStateNotInitialised;
       
   430             iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPClosed,
       
   431                                     EPbCmdClose, KErrNone);
       
   432             iClosedByAudioPolicy = EFalse;
       
   433             break;
       
   434             }
       
   435         case EPbApplyEffect:
       
   436             {
       
   437             // Re-init audio effects
       
   438             MPX_DEBUG1("CMPXLocalAudioPlayback::CommandL EPbApplyEffect");
       
   439             if( ( aData == KAudioEffectsID || aData == KEqualizerID ) &&
       
   440                 ( EStateInitialised == iState ) )
       
   441                 {
       
   442                 // Here we rely on CreateAudioEffectsL() to be safe to be called 
       
   443                 // in order to just set values again     
       
   444                 TRAPD(err, iAudioEffects->CreateAudioEffectsL() );
       
   445                 if(err)
       
   446                     {
       
   447                     MPX_DEBUG2("EPbApplyEffect err = %d", err);
       
   448                     // Sometimes we get KErrAccessDenied, then destroying effects
       
   449                     // and setting them again should help. This is a work-around, 
       
   450                     // and would be good to be fixed more properly.   
       
   451                     iAudioEffects->DestroyAudioEffect(); 
       
   452                     TRAPD(err, iAudioEffects->CreateAudioEffectsL() );
       
   453                     if(err)
       
   454                         {
       
   455                         MPX_DEBUG2("EPbApplyEffect again err = %d", err);
       
   456                         }
       
   457 					else
       
   458 						{
       
   459                         MPX_DEBUG1("EPbApplyEffect again set");
       
   460 						}
       
   461                     }
       
   462 				else
       
   463 					{
       
   464                     MPX_DEBUG1("EPbApplyEffect set");
       
   465 					}
       
   466                 iAudioEffectsOn = ETrue;
       
   467                 }
       
   468             break;
       
   469             }
       
   470         case EPbCmdCloseItem:
       
   471             {
       
   472             iDrmMediaUtility->Close();
       
   473             iPlayer->Close();
       
   474             iIsPlaying = EFalse;
       
   475             iFile.Close();
       
   476             iState = EStateNotInitialised;
       
   477             iClosedByAudioPolicy = EFalse;
       
   478             break;
       
   479             }
       
   480         case EPbCmdDisableEffect:
       
   481         	{
       
   482 			iAudioEffectsOn = EFalse;
       
   483 			break;
       
   484 			}
       
   485 		default:
       
   486 			break;
       
   487         }
       
   488     MPX_DEBUG3("<--CMPXLocalAudioPlayback::CommandL 0x%08x cmd %d", this, aCmd);
       
   489     }
       
   490 
       
   491 // ----------------------------------------------------------------------------
       
   492 // Sets a property of the plugin
       
   493 // ----------------------------------------------------------------------------
       
   494 //
       
   495 void CMPXLocalAudioPlayback::SetL(TMPXPlaybackProperty aProperty,TInt aValue)
       
   496     {
       
   497     MPX_DEBUG4("-->CMPXLocalAudioPlayback::SetL 0x%08x, (prop %d, val %d)",
       
   498                this, aProperty, aValue);
       
   499     TBool isSupported=ETrue;
       
   500     switch(aProperty)
       
   501         {
       
   502         case EPbPropertyVolume:
       
   503             {
       
   504             SetVolume( aValue, EFalse ); // don't notify MPX because playback engine converts EPSetComplete to EPropertyChanged
       
   505             break;
       
   506             }
       
   507         case EPbPropertyVolumeRamp:
       
   508             iPlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(TInt64(aValue)));
       
   509             break;
       
   510         case EPbPropertyMute:
       
   511             SetMute( aValue, EFalse ); // don't notify MPX because playback engine converts EPSetComplete to EPropertyChanged
       
   512             break;
       
   513         case EPbPropertyBalance:
       
   514             iPlayer->SetBalance(MMFBalance(aValue));
       
   515             break;
       
   516         case EPbPropertyPosition:
       
   517             {
       
   518             TInt64 pos(aValue);
       
   519             pos *= KPbMilliMultiplier;
       
   520             
       
   521             if (iIsPlaying)
       
   522                 {
       
   523                 iPlayer->Pause();
       
   524                 iPlayer->SetPosition(pos);
       
   525                 //Handle error of license expired when tapping the progress playing bar 
       
   526                 TRAPD( drmErr, ConsumeRightsL( ContentAccess::EContinue ) );
       
   527                 if ( drmErr == KErrCANoRights )
       
   528                     {
       
   529                     iDrmMediaUtility->Close();
       
   530                     iPlayer->Stop();
       
   531                     iIsPlaying = EFalse;
       
   532                     iAudioEffects->DestroyAudioEffect();
       
   533                     iPlayer->Close();
       
   534                     iObs->HandlePluginEvent(
       
   535                             MMPXPlaybackPluginObserver::EPStopped, 0, drmErr);
       
   536                     iFile.Close();
       
   537                     iState = EStateNotInitialised;
       
   538                     iObs->HandlePluginEvent(
       
   539                             MMPXPlaybackPluginObserver::EPClosed, EPbCmdStop,
       
   540                             drmErr);
       
   541                     iClosedByAudioPolicy = EFalse;
       
   542                     return;
       
   543                     }
       
   544                 iPlayer->Play();
       
   545                 }
       
   546             else
       
   547                 {
       
   548                 iPlayer->SetPosition(pos);
       
   549                 }
       
   550             }
       
   551             break;
       
   552         default:
       
   553             isSupported=EFalse;
       
   554         }
       
   555 
       
   556     if (!isSupported)
       
   557         {
       
   558         User::Leave(KErrNotSupported);
       
   559         }
       
   560     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPSetComplete,
       
   561                              aProperty, KErrNone);
       
   562     MPX_DEBUG4("<--CMPXLocalAudioPlayback::SetL 0x%08x, (prop %d, val %d)",
       
   563                this, aProperty, aValue);
       
   564     }
       
   565 
       
   566 // ----------------------------------------------------------------------------
       
   567 // Gets a property of the plugin (async)
       
   568 // ----------------------------------------------------------------------------
       
   569 //
       
   570 void CMPXLocalAudioPlayback::PropertyL(TMPXPlaybackProperty aProperty) const
       
   571     {
       
   572     MPX_DEBUG3("-->CMPXLocalAudioPlayback::PropertyL 0x%08x (prop %d)",
       
   573                this, aProperty);
       
   574     TBool isSupported=ETrue;
       
   575     TInt value=KErrNotFound;
       
   576     TInt err(KErrNone);
       
   577     switch(aProperty)
       
   578         {
       
   579         case EPbPropertyVolume:
       
   580             {
       
   581             value = iVolumeWatcher->CurrentValueL();
       
   582             break;
       
   583             }
       
   584         case EPbPropertyMaxVolume:
       
   585             value=iPlayer->MaxVolume();
       
   586             break;
       
   587         case EPbPropertyMute:
       
   588             value = iMuteWatcher->CurrentValueL();
       
   589             break;
       
   590         case EPbPropertyBalance:
       
   591             err = iPlayer->GetBalance(value);
       
   592             value=Balance(value);
       
   593             break;
       
   594         case EPbPropertyDuration:
       
   595             {
       
   596             TTimeIntervalMicroSeconds duration = iPlayer->Duration();
       
   597             value = duration.Int64() / KPbMilliMultiplier;
       
   598             }
       
   599             break;
       
   600         case EPbPropertyPosition:
       
   601             {
       
   602             TTimeIntervalMicroSeconds pos;
       
   603             iPlayer->GetPosition(pos);
       
   604             MPX_DEBUG2("CMPXLocalAudioPlayback::PropertyL position %ld", pos.Int64());
       
   605             value = pos.Int64() / KPbMilliMultiplier;
       
   606             }
       
   607             break;
       
   608         case EPbPropertySupportedFeatures:
       
   609             value = EPbFeatureBalance | EPbFeatureVolumeRamp;
       
   610             break;
       
   611         default:
       
   612             isSupported=EFalse;
       
   613         }
       
   614     if (!isSupported)
       
   615         {
       
   616         User::Leave(KErrNotSupported);
       
   617         }
       
   618     iObs->HandleProperty(aProperty,value,err);
       
   619     MPX_DEBUG3("<--CMPXLocalAudioPlayback::PropertyL 0x%08x (prop %d)",
       
   620                this, aProperty);
       
   621     }
       
   622 
       
   623 // ----------------------------------------------------------------------------
       
   624 // Gets a list of sub players, UPnP only
       
   625 // ----------------------------------------------------------------------------
       
   626 //
       
   627 void CMPXLocalAudioPlayback::SubPlayerNamesL()
       
   628     {
       
   629     iObs->HandleSubPlayerNames(KLocalPlaybackUid, NULL, ETrue, KErrNone);
       
   630     }
       
   631 
       
   632 // ----------------------------------------------------------------------------
       
   633 // Select a sub player
       
   634 // ----------------------------------------------------------------------------
       
   635 //
       
   636 void CMPXLocalAudioPlayback::SelectSubPlayerL(TInt /*aIndex*/)
       
   637     {
       
   638     User::Leave(KErrNotSupported);
       
   639     }
       
   640 
       
   641 // ----------------------------------------------------------------------------
       
   642 // Returns current sub player name
       
   643 // ----------------------------------------------------------------------------
       
   644 //
       
   645 const TDesC& CMPXLocalAudioPlayback::SubPlayerName()
       
   646     {
       
   647     return KNullDesC; //No subplayer name for local playback
       
   648     }
       
   649 
       
   650 // ----------------------------------------------------------------------------
       
   651 // Current sub player index
       
   652 // ----------------------------------------------------------------------------
       
   653 //
       
   654 TInt CMPXLocalAudioPlayback::SubPlayerIndex() const
       
   655    {
       
   656    return KErrNotFound;
       
   657    }
       
   658 
       
   659 // ----------------------------------------------------------------------------
       
   660 // Gets media properties
       
   661 // ----------------------------------------------------------------------------
       
   662 //
       
   663 void CMPXLocalAudioPlayback::MediaL(const TArray<TMPXAttribute>& aAttrs)
       
   664     {
       
   665     MPX_DEBUG2("-->CMPXLocalAudioPlayback::MediaL 0x%08x", this);
       
   666     RArray<TInt> suppIds;
       
   667     CleanupClosePushL(suppIds);
       
   668     suppIds.AppendL(KMPXMediaIdMusic);
       
   669     suppIds.AppendL(KMPXMediaIdGeneral);
       
   670     suppIds.AppendL(KMPXMediaIdAudio);
       
   671     suppIds.AppendL(KMPXMediaIdDrm);
       
   672     CMPXMedia* media=CMPXMedia::NewL(suppIds.Array());
       
   673     CleanupStack::PopAndDestroy(&suppIds);
       
   674     CleanupStack::PushL(media);
       
   675 
       
   676     if ( EStateInitialised == iState )
       
   677         {
       
   678         TUint attrG(0); // General attributes
       
   679         TUint attrA(0); // Audio attributes
       
   680         TUint attrM(0); // Music attributes
       
   681         TUint attrD(0); // DRM attributes
       
   682 
       
   683         for (TInt i=aAttrs.Count(); --i>=0;)
       
   684             {
       
   685             TMPXAttribute attr(aAttrs[i]);
       
   686             if (attr.ContentId() == KMPXMediaIdGeneral)
       
   687                 {
       
   688                 attrG |= attr.AttributeId();
       
   689                 }
       
   690             else if (attr.ContentId() == KMPXMediaIdMusic)
       
   691                 {
       
   692                 attrM |= attr.AttributeId();
       
   693                 }
       
   694             else if (attr.ContentId() == KMPXMediaIdAudio)
       
   695                 {
       
   696                 attrA |= attr.AttributeId();
       
   697                 }
       
   698             else if ( attr.ContentId() == KMPXMediaIdDrm )
       
   699                 {
       
   700                 attrD |= attr.AttributeId();
       
   701                 }
       
   702             }
       
   703 
       
   704         TInt metaCount = 0;
       
   705 
       
   706         // Get metadata from MMF
       
   707         TInt error = iPlayer->GetNumberOfMetaDataEntries(metaCount);
       
   708         CMMFMetaDataEntry* metaData = NULL;
       
   709 
       
   710         if (!error)
       
   711             {
       
   712             for (TInt i = 0; i < metaCount; ++i)
       
   713                 {
       
   714                 metaData = iPlayer->GetMetaDataEntryL(i);
       
   715                 CleanupStack::PushL(metaData);
       
   716 
       
   717                 if (metaData->Name().CompareF(KMMFMetaEntrySongTitle()) == 0 &&
       
   718                     attrG & EMPXMediaGeneralTitle)
       
   719                     { // TODO to check request
       
   720                     media->SetTextValueL(
       
   721                         TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralTitle),
       
   722                         metaData->Value());
       
   723                     }
       
   724                 else if (metaData->Name().CompareF(KMMFMetaEntryArtist()) == 0 &&
       
   725                     attrM & EMPXMediaMusicArtist)
       
   726                     {
       
   727                     media->SetTextValueL(
       
   728                         TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicArtist),
       
   729                         metaData->Value());
       
   730                     }
       
   731                 else if (metaData->Name().CompareF(KMMFMetaEntryAlbum()) == 0 &&
       
   732                     attrM & EMPXMediaMusicAlbum)
       
   733                     {
       
   734                     media->SetTextValueL(
       
   735                         TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicAlbum),
       
   736                         metaData->Value());
       
   737                     }
       
   738                 else if (metaData->Name().CompareF(KMMFMetaEntryYear()) == 0 &&
       
   739                     attrM & EMPXMediaMusicYear)
       
   740                     {
       
   741                     TInt year;
       
   742                     TLex lex( metaData->Value() );
       
   743                     lex.Val( year );
       
   744 
       
   745                     TDateTime dt;
       
   746                     dt.SetYear( year );
       
   747                     TTime time( dt );
       
   748 
       
   749                     media->SetTObjectValueL(
       
   750                         TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicYear),
       
   751                         time.Int64());
       
   752                     }
       
   753                 else if (metaData->Name().CompareF(KMMFMetaEntryComment()) == 0 &&
       
   754                     attrG & EMPXMediaGeneralComment)
       
   755                     {
       
   756                     media->SetTextValueL(
       
   757                         TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralComment),
       
   758                         metaData->Value());
       
   759                     }
       
   760                 else if (metaData->Name().CompareF(KMMFMetaEntryComposer()) == 0 &&
       
   761                     attrM & EMPXMediaMusicComposer)
       
   762                     {
       
   763                     media->SetTextValueL(
       
   764                         TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicComposer),
       
   765                         metaData->Value());
       
   766                     }
       
   767                 else if (metaData->Name().CompareF(KMMFMetaEntryAlbumTrack()) == 0 &&
       
   768                     attrM & EMPXMediaMusicAlbumTrack)
       
   769                     {
       
   770                     media->SetTextValueL(
       
   771                         TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicAlbumTrack),
       
   772                         metaData->Value());
       
   773                     }
       
   774                 else if (metaData->Name().CompareF(KMMFMetaEntryGenre()) == 0 &&
       
   775                     attrM & EMPXMediaMusicGenre)
       
   776                     {
       
   777                     media->SetTextValueL(
       
   778                         TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicGenre),
       
   779                         metaData->Value());
       
   780                     }
       
   781                 //else if (metaData->Name().CompareF(KMMFMetaEntryWOAF()) == 0 &&
       
   782                 //    attrM & EMPXMediaMusicGenre)
       
   783                 //    {
       
   784                     //media->SetTextValueL(
       
   785                     //    TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicGenre),
       
   786                     //    metaData->Value());
       
   787                     //}
       
   788                 else if (metaData->Name().CompareF(KMMFMetaEntryAPIC()) == 0 &&
       
   789                     attrM & EMPXMediaMusicAlbumArtFileName)
       
   790                     {
       
   791                     // TODO check collection if user defined album art available
       
   792                     media->SetTextValueL(
       
   793                         TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicAlbumArtFileName),
       
   794                         *iSong);
       
   795                     }
       
   796 
       
   797                 CleanupStack::PopAndDestroy(metaData);
       
   798                 metaData = NULL;
       
   799                 }
       
   800             if ( attrG & EMPXMediaGeneralTitle )
       
   801                 {
       
   802                 if ( !media->IsSupported(
       
   803                     TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralTitle ) ) )
       
   804                     {
       
   805                     TParsePtrC ptr( *iSong );
       
   806                     media->SetTextValueL(
       
   807                         TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralTitle),
       
   808                         ptr.Name() );
       
   809                     }
       
   810                 }
       
   811             }
       
   812         if (attrG & EMPXMediaGeneralUri)
       
   813             {
       
   814             media->SetTextValueL(
       
   815                 TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralUri),
       
   816                 *iSong);
       
   817             }
       
   818 
       
   819         if (attrG & EMPXMediaGeneralDuration)
       
   820             {
       
   821             TTimeIntervalMicroSeconds duration = iPlayer->Duration();
       
   822             media->SetTObjectValueL<TInt>(
       
   823                    TMPXAttribute(KMPXMediaIdGeneral, EMPXMediaGeneralDuration),
       
   824                    duration.Int64() / KPbMilliMultiplier);
       
   825             }
       
   826 
       
   827 
       
   828         // Set bitrate TODO
       
   829         TPckgBuf<TMMFAudioConfig> data;
       
   830 
       
   831         const TMMFMessageDestinationPckg
       
   832             destinationPckg(KUidInterfaceMMFAudioController);
       
   833 
       
   834         if (attrA & EMPXMediaAudioBitrate)
       
   835             {
       
   836             error = iPlayer->CustomCommandSync(destinationPckg,
       
   837                 EMMFAudioControllerGetSourceBitRate, KNullDesC8, KNullDesC8, data);
       
   838             if (!error)
       
   839                 {
       
   840                 media->SetTObjectValueL<TInt>(
       
   841                        TMPXAttribute(KMPXMediaIdAudio, EMPXMediaAudioBitrate),
       
   842                        data().iSampleRate);
       
   843                 }
       
   844             }
       
   845 
       
   846         if (attrA & EMPXMediaAudioSamplerate)
       
   847             {
       
   848 
       
   849             // Set sampling rate
       
   850             error = iPlayer->CustomCommandSync(destinationPckg,
       
   851                 EMMFAudioControllerGetSourceSampleRate, KNullDesC8, KNullDesC8, data);
       
   852             if (!error)
       
   853                 {
       
   854                 media->SetTObjectValueL<TInt>(
       
   855                        KMPXMediaAudioSamplerate,
       
   856                        data().iSampleRate);
       
   857                 }
       
   858             }
       
   859        if (attrG & EMPXMediaGeneralSize)
       
   860             {
       
   861             TEntry entry;
       
   862             iFs.Entry(iSong->Des(), entry);
       
   863             media->SetTObjectValueL<TInt>(
       
   864                    TMPXAttribute(KMPXMediaIdGeneral, EMPXMediaGeneralSize),
       
   865                    entry.iSize);
       
   866             }
       
   867 
       
   868        if (attrG & EMPXMediaGeneralMimeType)
       
   869             {
       
   870             RApaLsSession aps;
       
   871             error  = aps.Connect(); // always fail in console test
       
   872             if (KErrNone == error)
       
   873                 {
       
   874                 CleanupClosePushL(aps);
       
   875                 TDataType dataType;
       
   876                 TUid ignore;
       
   877                 if(aps.AppForDocument(iSong->Des(),ignore,dataType)==KErrNone)
       
   878                     {
       
   879                     media->SetTextValueL(
       
   880                         TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralMimeType),
       
   881                         dataType.Des());
       
   882                     }
       
   883                 CleanupStack::PopAndDestroy(&aps);
       
   884                 } // Notes, STIF console test always fail
       
   885             }
       
   886 
       
   887         // Set DRM info
       
   888         const CMPXMedia* drmMedia( iDrmMediaUtility->GetMediaL( attrD ));
       
   889         if ( drmMedia )
       
   890             {
       
   891             TInt count( drmMedia->Count() );
       
   892             for ( TInt i = 0; i < count; i++ )
       
   893                 {
       
   894                 TUint attrId( drmMedia->Attribute(i).AttributeId() );
       
   895                 if ( attrD & attrId )
       
   896                     {
       
   897                     TMPXAttribute mpxAtt( KMPXMediaIdDrm, attrId );
       
   898                     switch ( attrId )
       
   899                         {
       
   900                         case EMPXMediaDrmType:
       
   901                         case EMPXMediaDrmRightsStatus:
       
   902                         case EMPXMediaDrmRightsType:
       
   903                         case EMPXMediaDrmCount:
       
   904                             {
       
   905                             TInt val(
       
   906                                 drmMedia->ValueTObjectL<TInt>( mpxAtt ));
       
   907                             media->SetTObjectValueL( mpxAtt, val );
       
   908                             break;
       
   909                             }
       
   910                         case EMPXMediaDrmProtected:
       
   911                         case EMPXMediaDrmSendingAllowed:
       
   912                         case EMPXMediaDrmCanSetAutomated:
       
   913                         case EMPXMediaDrmHasInfoUrl:
       
   914                         case EMPXMediaDrmHasPreviewUrl:
       
   915                         case EMPXMediaDrmAboutToExpire:
       
   916                             {
       
   917                             TBool val(
       
   918                                 drmMedia->ValueTObjectL<TBool>( mpxAtt ));
       
   919                             media->SetTObjectValueL( mpxAtt, val );
       
   920                             break;
       
   921                             }
       
   922                         case EMPXMediaDrmStartTime:
       
   923                         case EMPXMediaDrmEndTime:
       
   924                         case EMPXMediaDrmIntervalStartTime:
       
   925                         case EMPXMediaDrmAccumulatedTime:
       
   926                             {
       
   927                             TInt64 val(
       
   928                                 drmMedia->ValueTObjectL<TInt64>( mpxAtt ));
       
   929                             media->SetTObjectValueL( mpxAtt, val );
       
   930                             break;
       
   931                             }
       
   932                         case EMPXMediaDrmInterval:
       
   933                             {
       
   934                             TTimeIntervalSeconds val(
       
   935                                 drmMedia->ValueTObjectL<TTimeIntervalSeconds>(mpxAtt));
       
   936                             media->SetTObjectValueL( mpxAtt, val );
       
   937                             break;
       
   938                             }
       
   939                         default:
       
   940                             {
       
   941                             break;
       
   942                             }
       
   943                         }   // end switch (attriId)
       
   944                     }   // end if ( attrD & attrId )
       
   945                 }
       
   946             }
       
   947         }
       
   948 
       
   949     iObs->HandleMedia(*media, KErrNone);
       
   950     CleanupStack::PopAndDestroy(media);
       
   951     MPX_DEBUG2("<--CMPXLocalAudioPlayback::MediaL 0x%08x", this);
       
   952     }
       
   953 
       
   954 // ----------------------------------------------------------------------------
       
   955 // Cancel request
       
   956 // ----------------------------------------------------------------------------
       
   957 //
       
   958 void CMPXLocalAudioPlayback::CancelRequest()
       
   959     {
       
   960     }
       
   961 
       
   962 // ----------------------------------------------------------------------------
       
   963 // File open complete event
       
   964 // ----------------------------------------------------------------------------
       
   965 //
       
   966 void CMPXLocalAudioPlayback::MapcInitComplete(TInt aError,
       
   967                                 const TTimeIntervalMicroSeconds& aDuration)
       
   968     {
       
   969     MPX_DEBUG4("-->CMPXLocalAudioPlayback::MapcInitComplete 0x%08x err (%d) duration (%Ld)",
       
   970                this, aError, aDuration.Int64());
       
   971     iState = EStateInitialised;
       
   972 
       
   973     // Restore volume level
       
   974     if ( KErrNone == aError )
       
   975         {
       
   976         TInt currentVol( 0 );
       
   977         MPX_TRAPD( volError, currentVol = iVolumeWatcher->CurrentValueL() );
       
   978         if ( volError == KErrNone )
       
   979             {
       
   980             SetVolume( currentVol );
       
   981             TBool mute( EFalse);
       
   982             MPX_TRAPD( muteError, mute = iMuteWatcher->CurrentValueL() );
       
   983             if ( muteError == KErrNone && mute )
       
   984                 {
       
   985                 SetMute(mute);
       
   986                 }
       
   987             }
       
   988         }
       
   989 
       
   990     // Disable automatic DRM consumption
       
   991     if ( iPlayer )
       
   992         {
       
   993         MMMFDRMCustomCommand* drmCustom = iPlayer->GetDRMCustomCommand();
       
   994         if ( drmCustom )
       
   995             {
       
   996             drmCustom->DisableAutomaticIntent( ETrue );
       
   997             }
       
   998         }
       
   999 
       
  1000     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPInitialised,
       
  1001                             aDuration.Int64()/KPbMilliMultiplier,aError);
       
  1002 
       
  1003     MPX_DEBUG4("<--CMPXLocalAudioPlayback::MapcInitComplete 0x%08x err (%d) duration (%Ld)",
       
  1004                this, aError, aDuration.Int64());
       
  1005     }
       
  1006 
       
  1007 // ----------------------------------------------------------------------------
       
  1008 // File play complete event
       
  1009 // ----------------------------------------------------------------------------
       
  1010 //
       
  1011 void CMPXLocalAudioPlayback::MapcPlayComplete(TInt aError)
       
  1012     {
       
  1013     MPX_DEBUG3("-->CMPXLocalAudioPlayback::MapcPlayComplete 0x%08x (err %d)",
       
  1014                this, aError);
       
  1015     iState = EStateNotInitialised;
       
  1016     iIsPlaying = EFalse;
       
  1017     if ( KErrNone != aError )
       
  1018         {
       
  1019         TRAP_IGNORE( ConsumeRightsL( ContentAccess::EPause ) );
       
  1020         }
       
  1021     else
       
  1022         {
       
  1023         TRAP_IGNORE( ConsumeRightsL( ContentAccess::EStop ) );
       
  1024         if ( iConsumeStarted )
       
  1025             {
       
  1026             iConsumeStarted = EFalse;
       
  1027             }
       
  1028         }
       
  1029 
       
  1030     TRAP_IGNORE( iAudioEffects->DestroyAudioEffect() );
       
  1031 
       
  1032     // If killed by audio policy, mimic a paused state
       
  1033     if ( KErrDied == aError || KErrAccessDenied == aError || KErrInUse == aError )
       
  1034         {
       
  1035         iClosedByAudioPolicy = ETrue;
       
  1036         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPaused,
       
  1037                                  0,
       
  1038                                  aError );
       
  1039         }
       
  1040      // If disk removed
       
  1041      else if( KErrNotReady == aError )
       
  1042         {
       
  1043         MPX_DEBUG1("CMPXLocalAudioPlayback::MapcPlayComplete - KErrNotReady");
       
  1044 
       
  1045         iClosedByAudioPolicy = EFalse;
       
  1046         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPStopped,
       
  1047                                  0,
       
  1048                                  KErrNone );
       
  1049         }
       
  1050     else
       
  1051         {
       
  1052         iClosedByAudioPolicy = EFalse;
       
  1053         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPlayComplete,0,aError);
       
  1054         }
       
  1055     MPX_DEBUG3("<--CMPXLocalAudioPlayback::MapcPlayComplete 0x%08x (err %d)",
       
  1056                this, aError);
       
  1057     }
       
  1058 
       
  1059 // ----------------------------------------------------------------------------
       
  1060 // Handle a change in a setting value.
       
  1061 // ----------------------------------------------------------------------------
       
  1062 //
       
  1063 void CMPXLocalAudioPlayback::HandleSettingChange(
       
  1064     const TUid& aRepositoryUid,
       
  1065     TUint32 aSettingId )
       
  1066     {
       
  1067     MPX_DEBUG2("-->CMPXLocalAudioPlayback::HandleSettingChange 0x%08x", this);
       
  1068 
       
  1069     if ( KCRUidMPXSettings == aRepositoryUid &&
       
  1070          KMPXPlaybackVolume == aSettingId )
       
  1071         {
       
  1072         MPX_DEBUG1("CMPXLocalAudioPlayback::HandleSettingChange() Volume setting changed");
       
  1073         TInt vol( 0 );
       
  1074         MPX_TRAPD( error, vol = iVolumeWatcher->CurrentValueL() );
       
  1075         if ( EStateInitialised == iState && error == KErrNone )
       
  1076             {
       
  1077             SetVolume( vol );
       
  1078             }
       
  1079         else if ( error == KErrNone )
       
  1080             {
       
  1081             // Do not need to set volume if not initialised,
       
  1082             // just notify observers
       
  1083             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPVolumeChanged,
       
  1084                                      vol,
       
  1085                                      KErrNone);
       
  1086             }
       
  1087         }
       
  1088     else if ( KCRUidMPXSettings == aRepositoryUid &&
       
  1089          KMPXPlaybackMute == aSettingId )
       
  1090         {
       
  1091         MPX_DEBUG1("CMPXLocalAudioPlayback::HandleSettingChange() Mute setting changed");
       
  1092         TBool mute( EFalse );
       
  1093         MPX_TRAPD( error, mute = static_cast<TBool>(iMuteWatcher->CurrentValueL()) );
       
  1094         if ( EStateInitialised == iState && error == KErrNone )
       
  1095             {
       
  1096             TInt oldVolume( 0 );
       
  1097             iPlayer->GetVolume( oldVolume );
       
  1098             if ( (mute && oldVolume != 0) || (!mute && oldVolume == 0) )
       
  1099                 {
       
  1100                 SetMute( mute );
       
  1101                 }
       
  1102             }
       
  1103         else if ( error == KErrNone )
       
  1104             {
       
  1105             // Do not need to set volume if not initialised,
       
  1106             // just notify observers
       
  1107             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
       
  1108                                      mute,
       
  1109                                      KErrNone);
       
  1110             }
       
  1111         }
       
  1112     MPX_DEBUG2("<--CMPXLocalAudioPlayback::HandleSettingChange 0x%08x", this);
       
  1113     }
       
  1114 
       
  1115 // ----------------------------------------------------------------------------
       
  1116 // Sets the volume level in audio controller
       
  1117 // ----------------------------------------------------------------------------
       
  1118 //
       
  1119 void CMPXLocalAudioPlayback::SetVolume( TInt aVolume, TBool aNotifyChange )
       
  1120     {
       
  1121     MPX_DEBUG3("-->CMPXLocalAudioPlayback::SetVolume 0x%08x vol (%d)", this, aVolume);
       
  1122 
       
  1123     // Ensure that level is within min and max values
       
  1124     if ( aVolume > KPbPlaybackVolumeLevelMax )
       
  1125         {
       
  1126         aVolume = KPbPlaybackVolumeLevelMax;
       
  1127         }
       
  1128     if ( aVolume < KPbPlaybackVolumeLevelMin )
       
  1129         {
       
  1130         aVolume = KPbPlaybackVolumeLevelMin;
       
  1131         }
       
  1132 
       
  1133     TBool changed( EFalse );
       
  1134     // Change MMF Audio player's volume
       
  1135     if ( EStateInitialised == iState )
       
  1136         {
       
  1137         TInt newVolume( aVolume * iPlayer->MaxVolume() / 100 );
       
  1138         MPX_DEBUG2("CMPXLocalAudioPlayback::SetVolume(): Setting volume = %d", newVolume);
       
  1139 
       
  1140         // First check if MMF Audio player's volume is changed by new value
       
  1141         TInt oldVolume( 0 );
       
  1142         iPlayer->GetVolume( oldVolume );
       
  1143         if ( newVolume != oldVolume )
       
  1144             {
       
  1145             iPlayer->SetVolume( newVolume );
       
  1146             changed = ETrue;
       
  1147             }
       
  1148         }
       
  1149 
       
  1150     // Change setting in cenrep
       
  1151     TInt currentVol( 0 );
       
  1152     MPX_TRAPD( volError, currentVol = iVolumeWatcher->CurrentValueL() );
       
  1153     if ( volError == KErrNone && aVolume != currentVol )
       
  1154         {
       
  1155         MPX_TRAP( volError, iVolumeWatcher->SetValueL( aVolume ) );
       
  1156         if( aVolume == 0 )
       
  1157             {
       
  1158             MPX_TRAP( volError, iMuteWatcher->SetValueL( ETrue ) );
       
  1159             }
       
  1160         else if( aVolume > 0 )
       
  1161             {
       
  1162             TBool currentMute( EFalse );
       
  1163             
       
  1164             MPX_TRAP( volError, currentMute = iMuteWatcher->CurrentValueL() );
       
  1165             if( volError == KErrNone && currentMute )
       
  1166                 {
       
  1167                 MPX_TRAP( volError, iMuteWatcher->SetValueL( EFalse ) );
       
  1168                 }
       
  1169             }
       
  1170         }
       
  1171     else if ( volError == KErrNone && aVolume == currentVol && changed )
       
  1172         {
       
  1173         // volume changed only to player after it has been initialised, 
       
  1174         // no need to reflect this to upper layers as the stored setting haven't changed
       
  1175         changed = EFalse;
       
  1176         }
       
  1177 
       
  1178     // Notify observer if value changed
       
  1179     if ( changed && aNotifyChange )
       
  1180         {
       
  1181         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPVolumeChanged,
       
  1182                                  aVolume,
       
  1183                                  KErrNone);
       
  1184         }
       
  1185 
       
  1186     MPX_DEBUG3("<--CMPXLocalAudioPlayback::SetVolume 0x%08x vol (%d)", this, aVolume);
       
  1187     }
       
  1188 
       
  1189 // ----------------------------------------------------------------------------
       
  1190 // Sets the volume level in audio controller
       
  1191 // ----------------------------------------------------------------------------
       
  1192 //
       
  1193 void CMPXLocalAudioPlayback::SetMute( TBool aMute, TBool aNotifyChange )
       
  1194     {
       
  1195     MPX_DEBUG3("-->CMPXLocalAudioPlayback::SetMute 0x%08x vol (%d)", this, aMute);
       
  1196 
       
  1197     TBool changed( EFalse );
       
  1198     // Change MMF Audio player's volume
       
  1199     if ( EStateInitialised == iState )
       
  1200         {
       
  1201         TInt currentVolume(0);
       
  1202         iPlayer->GetVolume(currentVolume);
       
  1203 		if ( aMute && currentVolume != 0 )
       
  1204 			{
       
  1205 			iVolume = currentVolume;
       
  1206 			iPlayer->SetVolume(0);
       
  1207 			changed = ETrue;
       
  1208 			}
       
  1209 		else if ( !aMute && currentVolume == 0 )      // UnMute
       
  1210 			{
       
  1211 			iPlayer->SetVolume(iVolume);
       
  1212 			changed = ETrue;
       
  1213 			}
       
  1214         }
       
  1215 
       
  1216     // Change setting in cenrep
       
  1217     TBool currentMute( EFalse );
       
  1218     MPX_TRAPD( muteError, currentMute = iMuteWatcher->CurrentValueL() );
       
  1219     if ( muteError == KErrNone )
       
  1220         {
       
  1221         if ( aMute && !currentMute )
       
  1222             {
       
  1223             MPX_TRAP( muteError, iMuteWatcher->SetValueL( aMute ) );
       
  1224             }
       
  1225         else if ( !aMute && currentMute )
       
  1226             {
       
  1227             MPX_TRAP( muteError, iMuteWatcher->SetValueL( aMute ) );
       
  1228             }
       
  1229         else if ( changed ) // Cenrep setting hasn't changed, no need to propagate to MPX
       
  1230             {
       
  1231             changed = EFalse;
       
  1232             }
       
  1233         }
       
  1234 
       
  1235     // Notify observer if value changed
       
  1236     if ( changed  && aNotifyChange )
       
  1237         {
       
  1238         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
       
  1239                                  aMute,
       
  1240                                  KErrNone);
       
  1241         }
       
  1242 
       
  1243     MPX_DEBUG3("<--CMPXLocalAudioPlayback::SetMute 0x%08x vol (%d)", this, aMute);
       
  1244     }
       
  1245 
       
  1246 // ----------------------------------------------------------------------------
       
  1247 // Consumes the rights for the current media
       
  1248 // ----------------------------------------------------------------------------
       
  1249 //
       
  1250 void CMPXLocalAudioPlayback::ConsumeRightsL(ContentAccess::TIntent aIntent)
       
  1251     {
       
  1252     MPX_FUNC("CMPXLocalAudioPlayback::ConsumeRightsL()");
       
  1253     // Fix for error: PNUI-7Q8GL6
       
  1254     // Normally,this case does not happen.
       
  1255     // In EStateInitialising state,consumerights is forbidden.
       
  1256     if ( iState == EStateInitialising )
       
  1257         {
       
  1258         return;
       
  1259         }
       
  1260     if ( iPlayer )
       
  1261         {
       
  1262         MMMFDRMCustomCommand* drmCustom = iPlayer->GetDRMCustomCommand();
       
  1263         if ( drmCustom )
       
  1264             {
       
  1265             switch ( aIntent )
       
  1266                 {
       
  1267                 case ContentAccess::EPlay:
       
  1268                 case ContentAccess::EStop:
       
  1269                 case ContentAccess::EPause:
       
  1270                 case ContentAccess::EContinue:
       
  1271                     {
       
  1272                     break;
       
  1273                     }
       
  1274                 default:
       
  1275                     {
       
  1276                     aIntent = ContentAccess::EUnknown;
       
  1277                     iConsumeStarted = EFalse;
       
  1278                     break;
       
  1279                     }
       
  1280                 }
       
  1281             TInt returnCode( drmCustom->ExecuteIntent(aIntent) );
       
  1282             MPX_DEBUG2("CMPXLocalAudioPlayback::ConsumeRightsL() ExecuteIntent return (%d)", returnCode);
       
  1283             User::LeaveIfError(returnCode);
       
  1284             }
       
  1285         }
       
  1286     }
       
  1287 // End of file