mpxmusicplayer/activeidle/aiplayerplugin/src/aiplayerplugin.cpp
branchRCL_3
changeset 11 13afc0e517bd
parent 5 2a40e88564c8
child 13 a914e47e7a01
child 14 943ff5625028
equal deleted inserted replaced
5:2a40e88564c8 11:13afc0e517bd
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Active Idle player plug-in
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ecom/implementationproxy.h>
       
    20 #include <aiutility.h>
       
    21 
       
    22 #include <AknUtils.h>
       
    23 #include <StringLoader.h>
       
    24 #include <bautils.h>
       
    25 #include <avkon.rsg>
       
    26 
       
    27 #include <data_caging_path_literals.hrh> 	// KDC_APP_BITMAP_DIR
       
    28 #include <apgcli.h>           				// RApaLsSession
       
    29 #include <apacmdln.h>         				// CApaCommandLine
       
    30 #include <apgtask.h>
       
    31 
       
    32 #include <mpxlog.h>
       
    33 #include <mpxconstants.h> 					// KAppUidMusicPlayer
       
    34 #include <mpxparameter.h>
       
    35 #include <mpxmusicplayerviewplugin.hrh>
       
    36 #include <aiplayerpluginresource.rsg>
       
    37 
       
    38 #include "aiplayerplugin.h"
       
    39 #include "aiplayerpluginuids.hrh"
       
    40 #include "aiplayerplugincontentmodel.h"
       
    41 
       
    42 _LIT(KMPXZeroDurationMark, "--");
       
    43 const TInt KMPXMinSecSeparatorIndex = 2;
       
    44 const TInt KMPXOneSecInMicroSecs = 1000000;
       
    45 const TInt KMPXOneHourInSeconds = 60*60;
       
    46 const TInt KMPXTimeIndicatorLength = 16;
       
    47 const TInt KPlayerMusicPlayerParameterGranularity = 50;
       
    48 _LIT( KMPXAiPlayerRscPath, "z:aiplayerpluginresource.rsc" );
       
    49 
       
    50 const TInt KMPlayerResumeWaitTime = 1000000; // 1.0s
       
    51 
       
    52 // ======== MEMBER FUNCTIONS ========
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CAiPlayerPlugin::ConstructL
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 void CAiPlayerPlugin::ConstructL()
       
    59     {
       
    60     MPX_DEBUG1("CAiPlayerPlugin::ConstructL() - begin");
       
    61 
       
    62     iInfo.iUid = KUidMusicPlayerPlugin;
       
    63     iInfo.iName.Copy(_L8("PlayerPlugin"));
       
    64 
       
    65     iContent   = AiUtility::CreateContentItemArrayIteratorL(KAiPlplContent);
       
    66     iResources = AiUtility::CreateContentItemArrayIteratorL(KAiPlplResources);
       
    67     iEvents    = AiUtility::CreateContentItemArrayIteratorL(KAiPlplEvents);
       
    68 
       
    69     // Read time format strings from AVKON resource
       
    70     iLongFormatString = StringLoader::LoadL(R_QTN_TIME_DURAT_LONG_WITH_ZERO);
       
    71     iShortFormatString = StringLoader::LoadL(R_QTN_TIME_DURAT_MIN_SEC_WITH_ZERO);
       
    72 
       
    73     iCoeEnv = CCoeEnv::Static();
       
    74 
       
    75     TParse parse;
       
    76     parse.Set(KMPXAiPlayerRscPath, &KDC_APP_RESOURCE_DIR, NULL);
       
    77     TFileName resourceFile;
       
    78     resourceFile.Append(parse.FullName());
       
    79     BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(), resourceFile);
       
    80     iResourceOffset = iCoeEnv->AddResourceFileL(resourceFile);
       
    81     iUnknownArtistText = StringLoader::LoadL(R_MPX_QTN_AIPP_UNKNOWN_ARTIST);
       
    82 
       
    83     iPlayStarted = EFalse;
       
    84     iCleanTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
    85 
       
    86     MPX_DEBUG1("CAiPlayerPlugin::ConstructL() - end");
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CAiPlayerPlugin::NewL
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 CAiPlayerPlugin* CAiPlayerPlugin::NewL()
       
    94     {
       
    95     CAiPlayerPlugin* self = new (ELeave) CAiPlayerPlugin;
       
    96     CleanupStack::PushL(self);
       
    97     self->ConstructL();
       
    98     CleanupStack::Pop(self);
       
    99     return self;
       
   100     }
       
   101 
       
   102 // ----------------------------------------------------------------------------
       
   103 // CAiPlayerPlugin::CAiPlayerPlugin
       
   104 // ----------------------------------------------------------------------------
       
   105 //
       
   106 CAiPlayerPlugin::CAiPlayerPlugin()
       
   107     : iEngine(NULL)
       
   108     {
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 // CAiPlayerPlugin::~CAiPlayerPlugin()
       
   113 // ----------------------------------------------------------------------------
       
   114 //
       
   115 CAiPlayerPlugin::~CAiPlayerPlugin()
       
   116     {
       
   117     iObservers.Close();
       
   118 
       
   119     Release( iContent );
       
   120     Release( iResources );
       
   121     Release( iEvents );
       
   122 
       
   123     if ( iResourceOffset )
       
   124         {
       
   125         iCoeEnv->DeleteResourceFile(iResourceOffset);
       
   126         }
       
   127 
       
   128     delete iEngine;
       
   129 
       
   130     delete iLongFormatString;
       
   131     delete iShortFormatString;
       
   132     delete iUnknownArtistText;
       
   133 
       
   134     iCoeEnv = NULL;
       
   135     iCleanTimer->Cancel();
       
   136     delete iCleanTimer;
       
   137     }
       
   138 
       
   139 // ----------------------------------------------------------------------------
       
   140 // CAiPlayerPlugin::Resume
       
   141 // ----------------------------------------------------------------------------
       
   142 //
       
   143 void CAiPlayerPlugin::Resume( TAiTransitionReason aReason )
       
   144     {
       
   145     MPX_DEBUG1("CAiPlayerPlugin::ResumeL");
       
   146     if ( !iEngine )
       
   147         {
       
   148         TRAPD(err, iEngine = CAiPlayerPluginEngine::NewL(*this));
       
   149         if ( err == KErrNone )
       
   150         	{
       
   151 			iState = iEngine->PlayerState();
       
   152 			PlayerStateChanged( iState );
       
   153 		    if (iState == EMPlayerStatePlaying || iState == EMPlayerStatePaused )
       
   154 				{
       
   155 				TrackInfoChanged( iEngine->Title(), iEngine->Artist() );
       
   156 				VolumeChanged( iEngine->Volume() );
       
   157 				PlaybackPositionChanged( iEngine->Position() );
       
   158 				}
       
   159 			}
       
   160         }
       
   161      else if ( aReason == EAiGeneralThemeChanged )
       
   162         {
       
   163         PlayerStateChanged( iEngine->PlayerState() );
       
   164         }
       
   165 
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CAiPlayerPlugin::Suspend
       
   170 // ----------------------------------------------------------------------------
       
   171 //
       
   172 void CAiPlayerPlugin::Suspend( TAiTransitionReason /*aReason*/ )
       
   173     {
       
   174     MPX_DEBUG1("CAiPlayerPlugin::Suspend");
       
   175     }
       
   176 
       
   177 // ----------------------------------------------------------------------------
       
   178 // CAiPlayerPlugin::Stop
       
   179 // ----------------------------------------------------------------------------
       
   180 //
       
   181 void CAiPlayerPlugin::Stop( TAiTransitionReason /*aReason*/ )
       
   182     {
       
   183     MPX_DEBUG1("CAiPlayerPlugin::Stop");
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------------------------------
       
   187 // CAiPlayerPlugin::SubscribeL
       
   188 // ----------------------------------------------------------------------------
       
   189 //
       
   190 void CAiPlayerPlugin::SubscribeL( MAiContentObserver& aObserver )
       
   191     {
       
   192     MPX_DEBUG1("CAiPlayerPlugin::SubscribeL");
       
   193     return iObservers.AppendL(&aObserver);
       
   194     }
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CAiPlayerPlugin::ConfigureL
       
   198 // ----------------------------------------------------------------------------
       
   199 //
       
   200 void CAiPlayerPlugin::ConfigureL( RAiSettingsItemArray& /*aSettings*/ )
       
   201     {
       
   202     MPX_DEBUG1("CAiPlayerPlugin::ConfigureL");
       
   203     }
       
   204 
       
   205 // ----------------------------------------------------------------------------
       
   206 // CAiPlayerPlugin::Extension
       
   207 // ----------------------------------------------------------------------------
       
   208 //
       
   209 TAny* CAiPlayerPlugin::Extension( TUid aUid )
       
   210     {
       
   211     if (aUid == KExtensionUidProperty)
       
   212         {
       
   213         return static_cast<MAiPropertyExtension*>(this);
       
   214         }
       
   215     else if (aUid == KExtensionUidEventHandler)
       
   216         {
       
   217         return static_cast<MAiEventHandlerExtension*>(this);
       
   218         }
       
   219     return NULL; // Requested extension not supported
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // CAiPlayerPlugin::GetPropertyL
       
   224 // ----------------------------------------------------------------------------
       
   225 //
       
   226 TAny* CAiPlayerPlugin::GetPropertyL( TInt aProperty )
       
   227     {
       
   228     switch (aProperty)
       
   229         {
       
   230         case EAiPublisherInfo:
       
   231         return &iInfo;
       
   232 
       
   233         case EAiPublisherContent:
       
   234         return static_cast<MAiContentItemIterator*>(iContent);
       
   235 
       
   236         case EAiPublisherResources:
       
   237         return static_cast<MAiContentItemIterator*>(iResources);
       
   238 
       
   239         case EAiPublisherEvents:
       
   240         return static_cast<MAiContentItemIterator*>(iEvents);
       
   241         }
       
   242 
       
   243     User::Leave(KErrNotSupported);
       
   244     return NULL;
       
   245     }
       
   246 
       
   247 // ----------------------------------------------------------------------------
       
   248 // CAiPlayerPlugin::SetPropertyL
       
   249 // ----------------------------------------------------------------------------
       
   250 //
       
   251 void CAiPlayerPlugin::SetPropertyL( TInt aProperty, TAny* aValue )
       
   252     {
       
   253     if (aValue)
       
   254         {
       
   255         switch (aProperty)
       
   256             {
       
   257             case EAiPublisherInfo:
       
   258                 {
       
   259                 const TAiPublisherInfo* info =
       
   260                     static_cast<const TAiPublisherInfo*>(aValue);
       
   261 
       
   262                 iInfo.iUid.iUid = info->iUid.iUid;
       
   263                 iInfo.iName.Copy( info->iName );
       
   264                 }
       
   265             break;
       
   266             }
       
   267         }
       
   268     }
       
   269 
       
   270 // ----------------------------------------------------------------------------
       
   271 // CAiPlayerPlugin::HandleEvent
       
   272 // ----------------------------------------------------------------------------
       
   273 //
       
   274 void CAiPlayerPlugin::HandleEvent( TInt aEvent, const TDesC& aParam )
       
   275     {
       
   276     MPX_DEBUG1("CAiPlayerPlugin::HandleEvent");
       
   277     TRAPD(err, DoHandleEventL( aEvent, aParam ) );
       
   278     if ( err != KErrNone )
       
   279     	{
       
   280 		MPX_DEBUG2("CAiPlayerPlugin::HandleEvent err[%d]", err);
       
   281 		}
       
   282     }
       
   283 
       
   284 // ----------------------------------------------------------------------------
       
   285 // CAiPlayerPlugin::DoHandleEventL
       
   286 // ----------------------------------------------------------------------------
       
   287 //
       
   288 void CAiPlayerPlugin::DoHandleEventL( TInt aEvent, const TDesC& aParam )
       
   289     {
       
   290     MPX_DEBUG2("CAiPlayerPlugin::DoHandleEventL %d", aEvent);
       
   291 
       
   292 	TInt volume = iEngine->Volume();
       
   293     switch (aEvent)
       
   294         {
       
   295         case EAiPlplEventVolInc:
       
   296             {
       
   297             iEngine->SetVolumeL(++volume);
       
   298             iLastSetVolume = volume;
       
   299             }
       
   300             break;
       
   301         case EAiPlplEventVolDec:
       
   302             {
       
   303             iEngine->SetVolumeL(--volume);
       
   304             iLastSetVolume = volume;
       
   305             }
       
   306             break;
       
   307     	case EAiPlplEventVolSet:
       
   308     		{
       
   309     		TLex lex;
       
   310     		lex.Assign(aParam);
       
   311     		if( lex.Val(volume) == KErrNone )
       
   312     		    {
       
   313         		iEngine->SetVolumeL(volume);
       
   314     		    }
       
   315             iLastSetVolume = volume;
       
   316     		}
       
   317         	break;
       
   318     	case EAiPlplEventVolMute:
       
   319     		{
       
   320     		iLastSetVolume = volume;
       
   321        		iEngine->SetVolumeL(0);
       
   322     		}
       
   323 	        break;
       
   324     	case EAiPlplEventVolRestore:
       
   325     		{
       
   326     		if( iLastSetVolume == 0 )
       
   327     		    {
       
   328     		    // So that "muting muted" don't function funky way.
       
   329     		    iLastSetVolume = 1;
       
   330     		    }
       
   331        		iEngine->SetVolumeL(iLastSetVolume);
       
   332     		}
       
   333 	        break;
       
   334         case EAiPlplEventLaunchLibrary:
       
   335             {
       
   336             MPX_DEBUG1("CAiPlayerPlugin::DoHandleEventL() EAiPlplEventLaunchLibrary");
       
   337             //Launch player
       
   338             TApaTaskList tasList(iEikonEnv->WsSession());
       
   339             TApaTask task = tasList.FindApp(KAppUidMusicPlayerX);
       
   340             if (task.Exists())
       
   341                 {
       
   342                 MPX_DEBUG1("CAiPlayerPlugin::DoHandleEventL() Music app is already launched. Go to Now Playing view.");
       
   343                 RWsSession& wsSession( iCoeEnv->WsSession() );
       
   344                 CMPXParameter* param = new ( ELeave ) CMPXParameter();
       
   345                 CleanupStack::PushL( param );
       
   346                 param->iType.iUid = KMPXPluginTypePlaybackUid;
       
   347                 param->iCmdForward = EMPXCmdFwdNowPlaying;
       
   348 
       
   349                 MPX_DEBUG1( "CAiPlayerPlugin::DoHandleEventL start Externalize" );
       
   350                 CBufBase* buffer = CBufFlat::NewL( KPlayerMusicPlayerParameterGranularity );
       
   351                 CleanupStack::PushL( buffer );
       
   352                 RBufWriteStream writeStream( *buffer );
       
   353                 CleanupClosePushL( writeStream );
       
   354                 param->ExternalizeL( writeStream );
       
   355                 writeStream.CommitL();
       
   356                 buffer->Compress();
       
   357                 CleanupStack::PopAndDestroy( &writeStream );
       
   358 
       
   359                 MPX_DEBUG2( "CAiPlayerPlugin::DoHandleEventL start Send message, message size = %d", buffer->Size() );
       
   360                 wsSession.SendMessageToWindowGroup( task.WgId(), KAppUidMusicPlayerX, buffer->Ptr( 0 ));
       
   361                 MPX_DEBUG1( "CAiPlayerPlugin::DoHandleEventL Send message complete" );
       
   362                 CleanupStack::PopAndDestroy( buffer );
       
   363                 CleanupStack::PopAndDestroy( param );
       
   364                 }
       
   365             else
       
   366                 {
       
   367 				// Launch Music Player Application
       
   368                 MPX_DEBUG1("CAiPlayerPlugin::DoHandleEventL() Launch Music app for the first time");
       
   369 				RProcess process;
       
   370 				TApaAppInfo appInfo;
       
   371 				RApaLsSession session;
       
   372 				TInt res = session.Connect(); // Ignore error
       
   373 				CleanupClosePushL( session );
       
   374 				TInt err = session.GetAppInfo( appInfo, KAppUidMusicPlayerX );
       
   375 				if ( !err )
       
   376 						{
       
   377 						process.Create( appInfo.iFullName, KNullDesC );// Ignore error
       
   378 						TRAP( err,
       
   379 							{
       
   380 							CApaCommandLine* commandLine = CApaCommandLine::NewLC();
       
   381 							commandLine->SetDocumentNameL( KNullDesC );
       
   382 							commandLine->SetExecutableNameL( appInfo.iFullName );
       
   383 							commandLine->SetProcessEnvironmentL( process );
       
   384 							session.StartApp( *commandLine ); // Ignore error
       
   385 							CleanupStack::PopAndDestroy(); // commandLine
       
   386 							});
       
   387 						process.Resume();
       
   388 						process.Close();
       
   389 						}
       
   390 				CleanupStack::PopAndDestroy(); // Close RApaLsSession session
       
   391                 }
       
   392             }
       
   393             break;
       
   394         default:
       
   395         	break;
       
   396         }
       
   397     }
       
   398 
       
   399 // ----------------------------------------------------------------------------
       
   400 // CAiPlayerPlugin::ClearL
       
   401 // ----------------------------------------------------------------------------
       
   402 //
       
   403 TInt CAiPlayerPlugin::ClearL(TAny* aPtr)
       
   404 	{
       
   405     MPX_DEBUG1("CAiPlayerPlugin::ClearL");
       
   406   	CAiPlayerPlugin* plugin = reinterpret_cast<CAiPlayerPlugin*> (aPtr);
       
   407     for (TInt i = 0; i < plugin->iObservers.Count(); i++)
       
   408     	{
       
   409         MAiContentObserver* observer = plugin->iObservers[i];
       
   410         observer->Clean((MAiPropertyExtension&) *plugin, EAiPlplContentArtistCaption, 1);
       
   411         observer->Clean((MAiPropertyExtension&) *plugin, EAiPlplContentTitleCaption, 1);
       
   412         observer->Clean((MAiPropertyExtension&) *plugin, EAiPlplContentDurationCaption, 1);
       
   413         observer->Clean((MAiPropertyExtension&) *plugin, EAiPlplContentElapsedTime,1);
       
   414         observer->Clean((MAiPropertyExtension&) *plugin, EAiPlplContentStatus, 1);
       
   415         observer->Clean((MAiPropertyExtension&) *plugin, EAiPlplContentVolume,1);
       
   416         observer->Commit(0);
       
   417     	}
       
   418     plugin->iCleanTimer->Cancel();
       
   419     return KErrNone;
       
   420 	}
       
   421 
       
   422 // -----------------------------------------------------------------------------
       
   423 // CAiPlayerPlugin::PlayerStateChanged
       
   424 // -----------------------------------------------------------------------------
       
   425 //
       
   426 void CAiPlayerPlugin::PlayerStateChanged( TMPlayerState aState )
       
   427     {
       
   428     MPX_DEBUG2("CAiPlayerPlugin::PlayerStateChanged [%d]", aState);
       
   429     iState = aState;
       
   430     for (TInt i = 0; i < iObservers.Count(); i++)
       
   431         {
       
   432         MAiContentObserver* observer = iObservers[i];
       
   433         observer->StartTransaction(reinterpret_cast<TInt32>(this));
       
   434         switch(iState)
       
   435             {
       
   436             case EMPlayerStatePlaying:
       
   437                 {
       
   438        			iPlayStarted = ETrue;
       
   439        			iCleanTimer->Cancel();
       
   440                 observer->Publish(*this,
       
   441                                   EAiPlplContentStatus,
       
   442                                   EAiPlplResourcePlayIcon,
       
   443                                   1);
       
   444                 }
       
   445                 break;
       
   446             case EMPlayerStatePaused:
       
   447                 {
       
   448        			iPlayStarted = ETrue;
       
   449                 iCleanTimer->Cancel();
       
   450                 observer->Publish(*this,
       
   451                                   EAiPlplContentStatus,
       
   452                                   EAiPlplResourcePauseIcon,
       
   453                                   1);
       
   454                 PlaybackPositionChanged(iEngine->Position());
       
   455                 }
       
   456                 break;
       
   457             case EMPlayerStateSeeking:
       
   458                 PlaybackPositionChanged(iEngine->Position());
       
   459                 break;
       
   460             default:    // EMPlayerStateOther
       
   461        			if ( iPlayStarted )
       
   462        				{
       
   463        				iCleanTimer->Start(KMPlayerResumeWaitTime,
       
   464        			                        KMPlayerResumeWaitTime,
       
   465        			                        TCallBack(ClearL,this));
       
   466        				}
       
   467        			iPlayStarted = EFalse;
       
   468                 break;
       
   469             }
       
   470         observer->Commit(reinterpret_cast<TInt32>(this));
       
   471         }
       
   472     }
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CAiPlayerPlugin::TrackInfoChanged
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 void CAiPlayerPlugin::TrackInfoChanged( const TDesC& aTitle, const TDesC& aArtist )
       
   479     {
       
   480     MPX_DEBUG1("CAiPlayerPlugin::TrackInfoChanged");
       
   481     for (TInt i = 0; i < iObservers.Count(); i++)
       
   482         {
       
   483         MAiContentObserver* observer = iObservers[i];
       
   484         observer->StartTransaction(reinterpret_cast<TInt32>(this));
       
   485 
       
   486         if ( &aTitle && aTitle.Length() ) //Check if hte reference exists add if is not empty
       
   487             {
       
   488             observer->Publish(*this, EAiPlplContentTitleCaption, aTitle, 1);
       
   489             }
       
   490         if ( &aArtist && aArtist.Length() ) //Check if hte reference exists add if is not empty
       
   491             {
       
   492             observer->Publish(*this, EAiPlplContentArtistCaption, aArtist, 1);
       
   493             }
       
   494         else
       
   495             {
       
   496             observer->Publish(*this, EAiPlplContentArtistCaption, *iUnknownArtistText, 1);
       
   497             }
       
   498         observer->Commit(reinterpret_cast<TInt32>(this));
       
   499         }
       
   500     }
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CAiPlayerPlugin::PlaybackPositionChanged
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 void CAiPlayerPlugin::PlaybackPositionChanged( TInt aPosition )
       
   507     {
       
   508     MPX_DEBUG1("CAiPlayerPlugin::PlaybackPositionChanged");
       
   509 
       
   510     TBuf<KMPXTimeIndicatorLength> elapsed;
       
   511     TBuf<KMPXTimeIndicatorLength> total;
       
   512 
       
   513     TInt64 playbackPosInSeconds;
       
   514     TInt64 totalLengthInSeconds;
       
   515 
       
   516     playbackPosInSeconds = aPosition;
       
   517     totalLengthInSeconds = iEngine->Duration();
       
   518 
       
   519     TPtrC format = *iShortFormatString;
       
   520 
       
   521     if (totalLengthInSeconds >= KMPXOneHourInSeconds)
       
   522         {
       
   523         // For tracks longer than an hour we use different time format and a
       
   524         // slightly different layout which has more space for the time labels.
       
   525         format.Set(*iLongFormatString);
       
   526         }
       
   527 
       
   528     TTime elapsedTime(playbackPosInSeconds * KMPXOneSecInMicroSecs);
       
   529     TTime totalTime(totalLengthInSeconds * KMPXOneSecInMicroSecs);
       
   530 
       
   531     if (aPosition == 0)
       
   532     	{
       
   533     	totalLengthInSeconds = 0;
       
   534     	}
       
   535 
       
   536     // Convert total playing time to texts.
       
   537     elapsedTime.FormatL(elapsed, format);
       
   538 
       
   539     if (totalLengthInSeconds)
       
   540         {
       
   541         // Time remaining
       
   542         totalTime.FormatL(total, format);
       
   543         }
       
   544     else
       
   545         {
       
   546         // Time remaining: --:--
       
   547         TLocale locale;
       
   548         TBuf<KMPXTimeIndicatorLength> pos;
       
   549         TChar separator = locale.TimeSeparator(KMPXMinSecSeparatorIndex);
       
   550         total = KMPXZeroDurationMark;
       
   551         total.Append(separator);
       
   552         total += KMPXZeroDurationMark;
       
   553         }
       
   554 
       
   555     AknTextUtils::LanguageSpecificNumberConversion(elapsed);
       
   556     AknTextUtils::LanguageSpecificNumberConversion(total);
       
   557 
       
   558     iElapsedTime.Copy(elapsed);
       
   559 
       
   560     iDuration.Copy(elapsed);
       
   561     iDuration.Append(_L("/"));
       
   562     iDuration.Append(total);
       
   563 
       
   564     if ( iState == EMPlayerStatePlaying || iState == EMPlayerStatePaused || iState == EMPlayerStateSeeking )
       
   565         {
       
   566         for (TInt i = 0; i < iObservers.Count(); i++)
       
   567             {
       
   568             MAiContentObserver* observer = iObservers[i];
       
   569             observer->StartTransaction(reinterpret_cast<TInt32>(this));
       
   570 
       
   571             //for (Classic view)
       
   572             observer->Publish(*this,
       
   573                            EAiPlplContentElapsedTime,
       
   574                            iElapsedTime,
       
   575                            1);
       
   576 
       
   577             //for (Navibar view)
       
   578             observer->Publish(*this,
       
   579                            EAiPlplContentDurationCaption,
       
   580                            iDuration,
       
   581                            1);
       
   582 
       
   583             observer->Commit(reinterpret_cast<TInt32>(this));
       
   584             }
       
   585         }
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CAiPlayerPlugin::VolumeChanged
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 void CAiPlayerPlugin::VolumeChanged( TInt aVolume )
       
   593     {
       
   594     MPX_DEBUG1("CAiPlayerPlugin::VolumeChanged");
       
   595 
       
   596     for (TInt i = 0; i < iObservers.Count(); i++)
       
   597         {
       
   598         MAiContentObserver* observer = iObservers[i];
       
   599         observer->StartTransaction(reinterpret_cast<TInt32>(this));
       
   600 
       
   601         // Order of enum TAiPlplPluginResourceIds is important
       
   602         // must stay EAiPlplResourceVol0= 0 ... EAiPlplResourceVol10 = 10
       
   603         // for this to work
       
   604         if ( aVolume>=0 && aVolume<=10 )
       
   605             {
       
   606             observer->Publish(*this,
       
   607                               EAiPlplContentVolume,
       
   608                               aVolume,
       
   609                               1);
       
   610             }
       
   611         observer->Commit(reinterpret_cast<TInt32>(this));
       
   612         }
       
   613     }
       
   614 
       
   615 // ======== GLOBAL FUNCTIONS ========
       
   616 
       
   617 // Provide a key pair value table for ECOM.
       
   618 // Used to identify the correct construction function for the requested interface.
       
   619 const TImplementationProxy ImplementationTable[] =
       
   620 {
       
   621     IMPLEMENTATION_PROXY_ENTRY( AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_PLAYERPLUGIN,
       
   622                                 CAiPlayerPlugin::NewL )
       
   623 };
       
   624 
       
   625 
       
   626 // Return an instance of the proxy table.
       
   627 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   628 {
       
   629     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   630     return ImplementationTable;
       
   631 }
       
   632