mpxplugins/serviceplugins/playbackplugins/progressdownloadsb/src/mpxprogressdownloadsb.cpp
changeset 0 ff3acec5bc43
child 2 b70d77332e66
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     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 manages progress download using Enhanced Media
       
    15                  Client API
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <f32plugin.h>
       
    22 #include <AudioPreference.h>
       
    23 #include <badesca.h>
       
    24 #include <mmf/common/mmfcontrollerframeworkbase.h>
       
    25 #include <mmf/common/mmfmeta.h>
       
    26 #include <mpxcommandgeneraldefs.h>
       
    27 #include <mpxmedia.h>
       
    28 #include <mpxplaybackpluginobserver.h>
       
    29 #include <mpxmediaaudiodefs.h>
       
    30 #include <mpxmediamusicdefs.h>
       
    31 #include <mpxmediageneraldefs.h>
       
    32 #include <mpxmediadrmdefs.h>
       
    33 #include <mpxcmn.h>
       
    34 #include <mpxdrmmediautility.h>
       
    35 #include <mpxprivatecrkeys.h>
       
    36 #include <mpxcenrepwatcher.h>
       
    37 #include <mpxlog.h>
       
    38 #include <pathinfo.h>
       
    39 
       
    40 #include <mmf/common/mmfdrmcustomcommands.h>
       
    41 #include <MetaDataUtility.h>
       
    42 #include <MetaDataFieldContainer.h>
       
    43 
       
    44 #include <MMControlFactory.h>
       
    45 using namespace multimedia;
       
    46 
       
    47 
       
    48 #include "mpxprogressdownloadsb.h"
       
    49 
       
    50 
       
    51 // CONSTANTS
       
    52 const TUid KProgressDownloadUid={0x10207BCD};
       
    53 
       
    54 // ============================ LOCAL FUNCTIONS ==============================
       
    55 
       
    56 
       
    57 // ============================ MEMBER FUNCTIONS ==============================
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // Two-phased constructor.
       
    61 // ----------------------------------------------------------------------------
       
    62 //
       
    63 CMPXProgressDownloadSB* CMPXProgressDownloadSB::NewL(TAny* /*aInitParams*/)
       
    64     {
       
    65     CMPXProgressDownloadSB* p=new(ELeave)CMPXProgressDownloadSB();
       
    66     CleanupStack::PushL(p);
       
    67     p->ConstructL();
       
    68     CleanupStack::Pop(p);
       
    69     return p;
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 void CMPXProgressDownloadSB::ConstructL()
       
    77     {
       
    78     iVolumeWatcher = CMPXCenRepWatcher::NewL(KCRUidMPXSettings,
       
    79                                              KMPXPlaybackVolume,
       
    80                                              this);
       
    81     iMuteWatcher = CMPXCenRepWatcher::NewL(KCRUidMPXSettings,
       
    82                                            KMPXPlaybackMute,
       
    83                                            this);
       
    84     iFeatureFlag = EPbFeatureBalance | EPbFeatureVolumeRamp;
       
    85     iDrmMediaUtility = CMPXDrmMediaUtility::NewL();
       
    86 
       
    87     //Create Factory
       
    88     TInt status = CMultimediaFactory::CreateFactory( iFactory );
       
    89     User::LeaveIfError(status);
       
    90 
       
    91     User::LeaveIfError(iFs.Connect());
       
    92 
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // C++ constructor
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 CMPXProgressDownloadSB::CMPXProgressDownloadSB()
       
   100     : iStreamBuffering(EFalse),
       
   101       iFirstBuffer(EFalse),
       
   102       iFileSaved(EFalse),
       
   103       iDownloadBytes(0),
       
   104       iDownloadSize(0),
       
   105       iFileHandle(NULL),
       
   106       iPdPath(NULL),
       
   107       iPlaying(EFalse),
       
   108       iOngoingCmdCancelDownload(EFalse),
       
   109       iErrorOfStreamClosedEvent(KErrNone)
       
   110     {}
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // Destructor
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 CMPXProgressDownloadSB::~CMPXProgressDownloadSB()
       
   117     {
       
   118     delete iMuteWatcher;
       
   119     delete iVolumeWatcher;
       
   120     if ( iDrmMediaUtility )
       
   121         {
       
   122         if ( EPbDlStateDownloadCompleted == iDownloadState )
       
   123             {
       
   124             ConsumeRights( ContentAccess::EStop );
       
   125             }
       
   126         iDrmMediaUtility->Close();
       
   127         delete iDrmMediaUtility;
       
   128         iDrmMediaUtility = NULL;
       
   129         }
       
   130 
       
   131     ResetEnhancedMediaClient();
       
   132     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPActive, EFalse, KErrNone);
       
   133 
       
   134     delete iFactory;
       
   135     iFactory = NULL;
       
   136     delete iPdPath;
       
   137     delete iDrmCustomCommand;
       
   138     iDrmCustomCommand = NULL;
       
   139 
       
   140     iFs.Close();
       
   141     }
       
   142 
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // Destructor
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 void CMPXProgressDownloadSB::ResetEnhancedMediaClient()
       
   149     {
       
   150 
       
   151     if (iMStreamControl)
       
   152         {
       
   153         iMStreamControl->Close();
       
   154         }
       
   155 
       
   156     if (iMAudioProgDLSource)
       
   157         {
       
   158         iMAudioProgDLSource->Close();
       
   159         }
       
   160 
       
   161     if(iFactory)
       
   162         {
       
   163         if(iMStreamControl)
       
   164             {
       
   165             iFactory->DeleteStreamControl(iMStreamControl);
       
   166             iMStreamControl = NULL;
       
   167             }
       
   168 
       
   169         if(iMAudioProgDLSource)
       
   170            {
       
   171            MSourceControl* objPtr = iMAudioProgDLSource;
       
   172            iFactory->DeleteSourceControl(objPtr);
       
   173            iMAudioProgDLSource = NULL;
       
   174            }
       
   175 
       
   176 
       
   177         if(iMAudioSink)
       
   178             {
       
   179             MSinkControl* objPtr = iMAudioSink;
       
   180             iFactory->DeleteSinkControl(objPtr);
       
   181             iMAudioSink = NULL;
       
   182             }
       
   183 
       
   184         if(iMVolumeControl)
       
   185             {
       
   186             MEffectControl* effectObj = iMVolumeControl;
       
   187             iFactory->DeleteEffectControl(effectObj);
       
   188             iMVolumeControl = NULL;
       
   189             }
       
   190         }
       
   191 
       
   192 
       
   193     }
       
   194 
       
   195 // ----------------------------------------------------------------------------
       
   196 // Initializes a song for playback
       
   197 // ----------------------------------------------------------------------------
       
   198 //
       
   199 void CMPXProgressDownloadSB::InitialiseL(const TDesC& aSong)
       
   200     {
       
   201     MPX_DEBUG2("CMPXProgressDownloadSB::InitialiseL(%S) entering", &aSong );
       
   202 
       
   203     // Re-initializes EMC to make sure multiple sequential
       
   204     // downloads work
       
   205     ResetEnhancedMediaClient();
       
   206 
       
   207     //Create Stream Source
       
   208     TInt err = iFactory->CreateStreamControl( KStreamControl, iMStreamControl );
       
   209     User::LeaveIfError(err);
       
   210     iMStreamControl->AddObserver( *this );
       
   211 
       
   212     //Create PD Source
       
   213     if ( iMStreamControl == NULL )
       
   214         {
       
   215         User::Leave(KErrNotReady);
       
   216         }
       
   217 
       
   218     if ( iMAudioProgDLSource != NULL )
       
   219         {
       
   220         User::Leave(KErrAlreadyExists);
       
   221         }
       
   222 
       
   223     MSourceControl* tempCtrl(NULL);
       
   224     err = iFactory->CreateSourceControl( KProgDLSourceControl, tempCtrl );
       
   225     User::LeaveIfError(err);
       
   226 
       
   227     iMAudioProgDLSource = static_cast<MProgDLSource*>(tempCtrl);
       
   228 
       
   229     //Open PDL Source
       
   230     err = iMAudioProgDLSource->Open(aSong, iTransactionId);
       
   231     User::LeaveIfError(err);
       
   232 
       
   233     err = iMAudioProgDLSource->AddObserver( *this );
       
   234      User::LeaveIfError(err);
       
   235 
       
   236     err = iMStreamControl->AddSource( *iMAudioProgDLSource );
       
   237     User::LeaveIfError(err);
       
   238 
       
   239 
       
   240     //Create Sink
       
   241     MSinkControl* tempSinkCtrl(NULL);
       
   242     err = iFactory->CreateSinkControl( KMMFAudioOutputSinkControl, tempSinkCtrl );
       
   243     User::LeaveIfError(err);
       
   244     iMAudioSink = tempSinkCtrl;
       
   245     iMStreamControl->AddSink( *iMAudioSink );
       
   246 
       
   247     //Create Volume Control
       
   248     MEffectControl* effectCtrl(NULL);
       
   249     err = iFactory->CreateEffectControl( KVolumeEffectControl, effectCtrl );
       
   250     User::LeaveIfError(err);
       
   251 
       
   252     iMVolumeControl = static_cast<MVolumeControl*>(effectCtrl);
       
   253     err = iMStreamControl->AddEffect( *iMVolumeControl );
       
   254 
       
   255     //Open Stream
       
   256     iMStreamControl->SetPriority( KAudioPriorityRealOnePlayer, KAudioPrefRealOneLocalPlayback );
       
   257     err =  iMStreamControl->Open();
       
   258     User::LeaveIfError(err);
       
   259     iStreamBuffering = ETrue;
       
   260 
       
   261     delete iPdPath;
       
   262     iPdPath = NULL;
       
   263     iPdPath = aSong.AllocL();
       
   264     iDownloadState = EPbDlStateBuffering;
       
   265     iState = EStateInitialising;
       
   266     iConsumeStarted = EFalse;
       
   267     iFileSaved = EFalse;
       
   268     MPX_DEBUG1("CMPXProgressDownloadSB::InitialiseL() exiting");
       
   269     }
       
   270 
       
   271 // ----------------------------------------------------------------------------
       
   272 // Initializes a song for playback
       
   273 // ----------------------------------------------------------------------------
       
   274 //
       
   275 void CMPXProgressDownloadSB::InitialiseL(RFile& /*aSong*/)
       
   276     {
       
   277     MPX_DEBUG1("CMPXProgressDownloadSB::InitialiseL(RFile) entering");
       
   278     User::Leave(KErrNotSupported);
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // Executes a command on the selected song
       
   283 // ----------------------------------------------------------------------------
       
   284 //
       
   285 void CMPXProgressDownloadSB::CommandL(
       
   286     TMPXPlaybackCommand aCmd,
       
   287     TInt /*aData*/)
       
   288     {
       
   289     MPX_DEBUG2("CMPXProgressDownloadSB::CommandL(%d) entering", aCmd);
       
   290 
       
   291     if ( iMStreamControl )
       
   292         {
       
   293         switch( aCmd )
       
   294             {
       
   295             case EPbCmdPlay:
       
   296                 {
       
   297                 if ( EPbDlStateDownloadCompleted == iDownloadState )
       
   298                     {
       
   299                     if ( iConsumeStarted )
       
   300                         {
       
   301                         ConsumeRights( ContentAccess::EContinue );
       
   302                         }
       
   303                     else
       
   304                         {
       
   305                         ConsumeRights( ContentAccess::EPlay );
       
   306                         iConsumeStarted = ETrue;
       
   307                         }
       
   308                     iMStreamControl->Start();
       
   309                     }
       
   310                 if ( iMStreamControl->GetState() == MStreamControl::EXECUTING )
       
   311                     {
       
   312                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPlaying,
       
   313                                              0, KErrNone);
       
   314                     }
       
   315                 else
       
   316                     {
       
   317                     iMStreamControl->Start();
       
   318                     }
       
   319 
       
   320                 break;
       
   321                 }
       
   322             case EPbCmdPause:
       
   323                 if ( EPbDlStateDownloadCompleted == iDownloadState && iConsumeStarted )
       
   324                     {
       
   325                     ConsumeRights( ContentAccess::EPause );
       
   326                     }
       
   327                 TInt ret = iMStreamControl->Pause();
       
   328                 iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPaused, 0, ret);
       
   329                 break;
       
   330             case EPbCmdStop:
       
   331                 iMStreamControl->Stop();
       
   332                 iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPStopped,
       
   333                                          0, KErrNone);
       
   334                 if ( EPbDlStateDownloadCompleted == iDownloadState && iConsumeStarted )
       
   335                     {
       
   336                     ConsumeRights( ContentAccess::EStop );
       
   337                     iConsumeStarted = EFalse;
       
   338                     if ( !iFileSaved )
       
   339                         {
       
   340                         iDrmMediaUtility->Close(); // release file handle so we can move file.
       
   341                         MoveDownloadedFileToMusicFolderL();
       
   342                         }
       
   343                     }
       
   344                 iDrmMediaUtility->Close();
       
   345                 break;
       
   346             case EPbCmdClose:
       
   347                 if ( EPbDlStateDownloadCompleted == iDownloadState && iConsumeStarted  )
       
   348                     {
       
   349                     ConsumeRights( ContentAccess::EStop );
       
   350                     iConsumeStarted = EFalse;
       
   351                     if ( !iFileSaved )
       
   352                         {
       
   353                         iDrmMediaUtility->Close(); // release file handle so we can move file.
       
   354                         MoveDownloadedFileToMusicFolderL();
       
   355                         }
       
   356                     }
       
   357                 iDrmMediaUtility->Close();
       
   358                 iState = EStateNotInitialised;
       
   359                 iDownloadState = EPbDlStateNotDownloading;
       
   360                 iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPClosed,
       
   361                                          0, KErrNone);
       
   362                 break;
       
   363             }
       
   364         }
       
   365 
       
   366     MPX_DEBUG1("CMPXProgressDownloadSB::CommandL() exiting");
       
   367     }
       
   368 
       
   369 // ----------------------------------------------------------------------------
       
   370 // Executes a command
       
   371 // ----------------------------------------------------------------------------
       
   372 //
       
   373 void CMPXProgressDownloadSB::CommandL( CMPXCommand& aCmd )
       
   374     {
       
   375     MPX_FUNC("CMPXProgressDownloadSB::CommandL(CMPXCommand)");
       
   376 
       
   377     ASSERT( aCmd.IsSupported( KMPXCommandGeneralId ));
       
   378     TInt id( *aCmd.Value<TInt>( KMPXCommandGeneralId ));
       
   379     if ( KMPXCommandIdPlaybackPD == id )
       
   380         {
       
   381         ASSERT(aCmd.IsSupported(KMPXCommandPlaybackGeneralType));
       
   382         TMPXPlaybackPdCommand cmd(
       
   383             static_cast<TMPXPlaybackPdCommand>(
       
   384                 *aCmd.Value<TInt>(KMPXCommandPlaybackGeneralType)));
       
   385         switch ( cmd )
       
   386             {
       
   387             case ( EPbCmdStartPd ):
       
   388                 {
       
   389                 ASSERT( aCmd.IsSupported( KMPXCommandPlaybackPDTransactionID ));
       
   390                 iTransactionId = *aCmd.Value<TUint>( KMPXCommandPlaybackPDTransactionID );
       
   391                 break;
       
   392                 }
       
   393             case ( EPbCmdFinishPd ):
       
   394                 {
       
   395                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlayComplete,
       
   396                                          0,KErrNone);
       
   397                 break;
       
   398                 }
       
   399             case ( EPbCmdGetPdStatus ):
       
   400                 {
       
   401                 aCmd.SetTObjectValueL<TUint>(
       
   402                         KMPXCommandPlaybackPDTransactionID,
       
   403                         iTransactionId );
       
   404                 aCmd.SetTObjectValueL<TMPXPlaybackPdDownloadState>(
       
   405                         KMPXCommandPlaybackPDState,
       
   406                         static_cast<TMPXPlaybackPdDownloadState>(iDownloadState));
       
   407                 aCmd.SetTObjectValueL<TInt>(
       
   408                         KMPXCommandPlaybackPDDownloadedBytes,
       
   409                         iDownloadBytes );
       
   410                 aCmd.SetTObjectValueL<TInt>(
       
   411                         KMPXCommandPlaybackPDTotalBytes,
       
   412                         iDownloadSize );
       
   413                 break;
       
   414                 }
       
   415             case ( EPbCmdPausePd ):
       
   416                 {
       
   417                 iObs->HandlePluginEvent(
       
   418                         MMPXPlaybackPluginObserver::EPDownloadCmdPauseDownload,
       
   419                         iTransactionId,
       
   420                         KErrNone );
       
   421                 break;
       
   422                 }
       
   423             case ( EPbCmdResumePd ):
       
   424                 {
       
   425                 iMAudioProgDLSource->ResumeDownload();
       
   426 
       
   427                 iObs->HandlePluginEvent(
       
   428                         MMPXPlaybackPluginObserver::EPDownloadCmdResumeDownload,
       
   429                         iTransactionId,
       
   430                         KErrNone );
       
   431                 break;
       
   432                 }
       
   433             case ( EPbCmdCancelPd ):
       
   434                 {
       
   435 
       
   436                 iMStreamControl->Stop();
       
   437                 iMStreamControl->Close();
       
   438                 iMAudioProgDLSource->CancelDownload();
       
   439                 iOngoingCmdCancelDownload = ETrue;
       
   440                 iObs->HandlePluginEvent(
       
   441                         MMPXPlaybackPluginObserver::EPDownloadCmdCancelDownload,
       
   442                         iTransactionId,
       
   443                         KErrNone);
       
   444                 break;
       
   445                 }
       
   446             default:
       
   447                 break;
       
   448             }
       
   449         }
       
   450     }
       
   451 
       
   452 // ----------------------------------------------------------------------------
       
   453 // Sets a property of the plugin
       
   454 // ----------------------------------------------------------------------------
       
   455 //
       
   456 void CMPXProgressDownloadSB::SetL(
       
   457     TMPXPlaybackProperty aProperty,
       
   458     TInt aValue)
       
   459     {
       
   460     MPX_DEBUG3("CMPXProgressDownloadSB::SetL(%d, %d) entering", aProperty, aValue);
       
   461 
       
   462     TBool isSupported=ETrue;
       
   463     switch(aProperty)
       
   464         {
       
   465         case EPbPropertyVolume:
       
   466             {
       
   467             SetVolume(aValue);
       
   468             }
       
   469             break;
       
   470         case EPbPropertyVolumeRamp:
       
   471             {
       
   472             TInt curVol = 0;
       
   473             MVolumeControl::TVolumeRampMode aMode = MVolumeControl::EIMMEDIATE;
       
   474             TUint64 duration = aValue;
       
   475             TInt err = iMVolumeControl->GetVolume(curVol);
       
   476             if(iMVolumeControl)
       
   477                 {
       
   478                 iMVolumeControl->SetVolumeRamp(0, curVol, duration, aMode);
       
   479                 iMVolumeControl->Apply();
       
   480                 }
       
   481             }
       
   482             break;
       
   483         case EPbPropertyMute:
       
   484             SetMute( aValue );
       
   485             break;
       
   486         case EPbPropertyBalance:
       
   487             break;
       
   488         default:
       
   489             isSupported=EFalse;
       
   490         }
       
   491 
       
   492     if (!isSupported)
       
   493         {
       
   494         User::Leave(KErrNotSupported);
       
   495         }
       
   496     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPSetComplete,
       
   497                              aProperty, KErrNone);
       
   498 
       
   499     MPX_DEBUG1("CMPXProgressDownloadSB::SetL() exiting");
       
   500     }
       
   501 
       
   502 // ----------------------------------------------------------------------------
       
   503 // Gets a property of the plugin (async)
       
   504 // ----------------------------------------------------------------------------
       
   505 //
       
   506 void CMPXProgressDownloadSB::PropertyL(TMPXPlaybackProperty aProperty) const
       
   507     {
       
   508     MPX_DEBUG2("CMPXProgressDownloadSB::ValueL(%d) entering", aProperty);
       
   509 
       
   510     TBool isSupported=ETrue;
       
   511     TInt value=KErrNotFound;
       
   512     TInt err(KErrNone);
       
   513     switch(aProperty)
       
   514         {
       
   515         case EPbPropertyVolume:
       
   516             value = iVolumeWatcher->CurrentValueL();
       
   517             break;
       
   518         case EPbPropertyMaxVolume:
       
   519             iMVolumeControl->GetMaxVolume(value);
       
   520             break;
       
   521         case EPbPropertyMute:
       
   522             value = iMuteWatcher->CurrentValueL();
       
   523             break;
       
   524         case EPbPropertyBalance:
       
   525             //err = iPdPlayer->GetBalance(value);
       
   526             //value=Balance(value);
       
   527             break;
       
   528         case EPbPropertyDuration:
       
   529             {
       
   530             TInt64 duration;
       
   531             iMStreamControl->GetDuration(duration);
       
   532             value = duration / KPbMilliMultiplier;
       
   533             }
       
   534             break;
       
   535         case EPbPropertyPosition:
       
   536             {
       
   537             TInt64 pos;
       
   538             iMStreamControl->GetPosition(pos);
       
   539             value = pos / KPbMilliMultiplier;
       
   540             }
       
   541             break;
       
   542         case EPbPropertySupportedFeatures:
       
   543             value = iFeatureFlag;
       
   544             break;
       
   545         default:
       
   546             isSupported=EFalse;
       
   547         }
       
   548     if (!isSupported)
       
   549         {
       
   550         User::Leave(KErrNotSupported);
       
   551         }
       
   552     iObs->HandleProperty(aProperty,value,err);
       
   553 
       
   554     MPX_DEBUG1("CMPXProgressDownloadSB::ValueL() exiting");
       
   555     }
       
   556 
       
   557 // ----------------------------------------------------------------------------
       
   558 // Gets a list of sub players, UPnP only
       
   559 // ----------------------------------------------------------------------------
       
   560 //
       
   561 void CMPXProgressDownloadSB::SubPlayerNamesL()
       
   562     {
       
   563     iObs->HandleSubPlayerNames(KProgressDownloadUid, NULL, ETrue, KErrNone);
       
   564     }
       
   565 
       
   566 // ----------------------------------------------------------------------------
       
   567 // Select a sub player
       
   568 // ----------------------------------------------------------------------------
       
   569 //
       
   570 void CMPXProgressDownloadSB::SelectSubPlayerL(TInt /*aIndex*/)
       
   571     {
       
   572     User::Leave(KErrNotSupported);
       
   573     }
       
   574 
       
   575 // ----------------------------------------------------------------------------
       
   576 // Returns current sub player name
       
   577 // ----------------------------------------------------------------------------
       
   578 //
       
   579 const TDesC& CMPXProgressDownloadSB::SubPlayerName()
       
   580     {
       
   581     return KNullDesC; //No subplayer name for local playback
       
   582     }
       
   583 
       
   584 // ----------------------------------------------------------------------------
       
   585 // Current sub player index
       
   586 // ----------------------------------------------------------------------------
       
   587 //
       
   588 TInt CMPXProgressDownloadSB::SubPlayerIndex() const
       
   589    {
       
   590    return KErrNotFound;
       
   591    }
       
   592 
       
   593 // ----------------------------------------------------------------------------
       
   594 // Gets media properties
       
   595 // ----------------------------------------------------------------------------
       
   596 //
       
   597 void CMPXProgressDownloadSB::MediaL(const TArray<TMPXAttribute>& aAttrs)
       
   598     {
       
   599     MPX_DEBUG1("CMPXProgressDownloadSB::MediaL() entering");
       
   600 
       
   601     RArray<TInt> suppIds;
       
   602     CleanupClosePushL(suppIds);
       
   603     suppIds.AppendL(KMPXMediaIdMusic);
       
   604     suppIds.AppendL(KMPXMediaIdGeneral);
       
   605     suppIds.AppendL(KMPXMediaIdAudio);
       
   606     CMPXMedia* media=CMPXMedia::NewL(suppIds.Array());
       
   607     CleanupStack::PopAndDestroy(&suppIds);
       
   608     CleanupStack::PushL(media);
       
   609 
       
   610     TUint attrG(0); // General attributes
       
   611     TUint attrA(0); // Audio attributes
       
   612     TUint attrM(0); // Music attributes
       
   613     TUint attrD(0); // DRM attributes
       
   614 
       
   615     TInt error(KErrNone);
       
   616 
       
   617     for (TInt i=aAttrs.Count(); --i>=0;)
       
   618         {
       
   619         TMPXAttribute attr(aAttrs[i]);
       
   620         if (attr.ContentId() == KMPXMediaIdGeneral)
       
   621             {
       
   622             attrG |= attr.AttributeId();
       
   623             }
       
   624         else if (attr.ContentId() == KMPXMediaIdMusic)
       
   625             {
       
   626             attrM |= attr.AttributeId();
       
   627             }
       
   628         else if (attr.ContentId() == KMPXMediaIdAudio)
       
   629             {
       
   630             attrA |= attr.AttributeId();
       
   631             }
       
   632         else if ( attr.ContentId() == KMPXMediaIdDrm )
       
   633             {
       
   634             attrD |= attr.AttributeId();
       
   635             }
       
   636         }
       
   637 
       
   638 
       
   639     // Get the mime type
       
   640 
       
   641     RApaLsSession aps;
       
   642     error  = aps.Connect(); // always fail in console test
       
   643     if ( KErrNone == error )
       
   644         {
       
   645         CleanupClosePushL(aps);
       
   646         TUid ignore;
       
   647         aps.AppForDocument( iPdPath->Des(), ignore, iMimeType );
       
   648         CleanupStack::PopAndDestroy(&aps);
       
   649         }
       
   650 
       
   651     //MPX_DEBUG2("CMPXProgressDownloadSB::MediaL() mime type = %S", iMimeType.Des8().Ptr() );
       
   652 
       
   653 	if ( iPlaying )
       
   654 	{
       
   655 
       
   656     CMetaDataUtility *metaDataUtility = CMetaDataUtility::NewL();
       
   657     CleanupStack::PushL( metaDataUtility );
       
   658 
       
   659     TInt err = KErrNone;
       
   660     if ( iMimeType.Des8().Length() )
       
   661         {
       
   662         if ( iFileHandle )
       
   663             {
       
   664             TRAP( err, metaDataUtility->OpenFileL( *iFileHandle, iMimeType.Des8() ) );
       
   665             }
       
   666         else
       
   667             {
       
   668             TRAP( err, metaDataUtility->OpenFileL( *iPdPath, iMimeType.Des8() ) );
       
   669             }
       
   670         }
       
   671     else
       
   672         {
       
   673         if ( iFileHandle )
       
   674             {
       
   675             TRAP( err, metaDataUtility->OpenFileL( *iFileHandle ) );
       
   676             }
       
   677         else
       
   678             {
       
   679             TRAP( err, metaDataUtility->OpenFileL( *iPdPath ) );
       
   680             }
       
   681         }
       
   682 
       
   683     MPX_DEBUG2("CMPXProgressDownloadSB::MediaL() Metadata utility error = %d", err);
       
   684 
       
   685 
       
   686     if ( err == KErrNone )
       
   687         {
       
   688         // Get number of metadata
       
   689         TInt count = metaDataUtility->MetaDataCount();
       
   690         for( TInt i = 0; i < count; i++ )
       
   691             {
       
   692             TMetaDataFieldId fieldId;
       
   693 
       
   694             TPtrC field = metaDataUtility->MetaDataFieldsL().At( i, fieldId );
       
   695             if( field != KNullDesC )
       
   696                 {
       
   697                 switch( fieldId )
       
   698                     {
       
   699                     case EMetaDataSongTitle:
       
   700                         {
       
   701                         if ( attrG & EMPXMediaGeneralTitle )
       
   702                             {
       
   703                             media->SetTextValueL(
       
   704                                 TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralTitle),
       
   705                                 field );
       
   706                             }
       
   707                         break;
       
   708                         }
       
   709                     case EMetaDataArtist:
       
   710                         {
       
   711                         if ( attrM & EMPXMediaMusicArtist )
       
   712                             {
       
   713                             media->SetTextValueL(
       
   714                                 TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicArtist),
       
   715                                 field );
       
   716                             }
       
   717                         break;
       
   718                         }
       
   719                     case EMetaDataAlbum:
       
   720                         {
       
   721                         if ( attrM & EMPXMediaMusicAlbum )
       
   722                             {
       
   723                             media->SetTextValueL(
       
   724                                 TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicAlbum),
       
   725                                 field );
       
   726                             }
       
   727                         break;
       
   728                         }
       
   729                     case EMetaDataYear:
       
   730                         {
       
   731                         if ( attrM & EMPXMediaMusicYear )
       
   732                             {
       
   733                             TInt year;
       
   734                             TLex lex( field );
       
   735                             lex.Val( year );
       
   736 
       
   737                             TDateTime dt;
       
   738                             dt.SetYear( year );
       
   739                             TTime time( dt );
       
   740 
       
   741                             media->SetTObjectValueL(
       
   742                                     TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicYear),
       
   743                                     time.Int64());
       
   744                             }
       
   745                         break;
       
   746                         }
       
   747                     case EMetaDataAlbumTrack:
       
   748                         {
       
   749                         if ( attrM & EMPXMediaMusicAlbumTrack )
       
   750                             {
       
   751                             media->SetTextValueL(
       
   752                                 TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicAlbumTrack),
       
   753                                 field );
       
   754                             }
       
   755                         break;
       
   756                         }
       
   757                     case EMetaDataGenre:
       
   758                         {
       
   759                         if ( attrM & EMPXMediaMusicGenre )
       
   760                             {
       
   761                             media->SetTextValueL(
       
   762                                 TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicGenre),
       
   763                                 field );
       
   764                             }
       
   765                         break;
       
   766                         }
       
   767                     case EMetaDataComposer:
       
   768                         {
       
   769                         if ( attrM & EMPXMediaMusicComposer )
       
   770                             {
       
   771                             media->SetTextValueL(
       
   772                                 TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicComposer),
       
   773                                 field );
       
   774                             }
       
   775                         break;
       
   776                         }
       
   777                     case EMetaDataComment:
       
   778                         {
       
   779                         if ( attrG & EMPXMediaGeneralComment )
       
   780                             {
       
   781                             media->SetTextValueL(
       
   782                                 TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralComment),
       
   783                                 field );
       
   784                             }
       
   785                         break;
       
   786                         }
       
   787                     case EMetaDataJpeg:
       
   788                         if ( attrM & EMPXMediaMusicAlbumArtFileName )
       
   789                             {
       
   790                             media->SetTextValueL(
       
   791                                 TMPXAttribute(KMPXMediaIdMusic,EMPXMediaMusicAlbumArtFileName),
       
   792                                 *iPdPath);
       
   793                             }
       
   794                          break;
       
   795                     default:
       
   796                         {
       
   797                         // nothing to do
       
   798                         break;
       
   799                         }
       
   800                     }
       
   801                 }
       
   802             }
       
   803         }
       
   804 
       
   805     metaDataUtility->ResetL();
       
   806     CleanupStack::PopAndDestroy(metaDataUtility);
       
   807 
       
   808 	}
       
   809 
       
   810 
       
   811    if (attrG & EMPXMediaGeneralUri)
       
   812         {
       
   813         media->SetTextValueL(
       
   814             TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralUri),
       
   815             *iPdPath);
       
   816         }
       
   817 
       
   818    if (attrG & EMPXMediaGeneralDuration)
       
   819         {
       
   820         TInt64 duration;
       
   821         iMStreamControl->GetDuration(duration);
       
   822         media->SetTObjectValueL<TInt>(
       
   823                TMPXAttribute(KMPXMediaIdGeneral, EMPXMediaGeneralDuration),
       
   824                duration/ KPbMilliMultiplier);
       
   825         }
       
   826 
       
   827 
       
   828     // Set bitrate
       
   829     if (attrA & EMPXMediaAudioBitrate)
       
   830         {
       
   831         TUint bitRate;
       
   832         error = iMAudioProgDLSource->GetBitRate(bitRate);
       
   833 
       
   834         if (!error)
       
   835             {
       
   836             media->SetTObjectValueL<TInt>(
       
   837                    TMPXAttribute(KMPXMediaIdAudio, EMPXMediaAudioBitrate),
       
   838                    bitRate);
       
   839             }
       
   840         }
       
   841 
       
   842     if (attrA & EMPXMediaAudioSamplerate)
       
   843         {
       
   844         // TODO: How to get sampling rate through ProgDLSource?
       
   845 
       
   846         }
       
   847 
       
   848    if (attrG & EMPXMediaGeneralSize)
       
   849         {
       
   850         RFs fs;
       
   851         User::LeaveIfError(fs.Connect());
       
   852         CleanupClosePushL(fs);
       
   853         TEntry entry;
       
   854         fs.Entry(iPdPath->Des(), entry);
       
   855         media->SetTObjectValueL<TInt>(
       
   856                TMPXAttribute(KMPXMediaIdGeneral, EMPXMediaGeneralSize),
       
   857                entry.iSize);
       
   858         CleanupStack::PopAndDestroy(&fs);
       
   859         }
       
   860 
       
   861    if (attrG & EMPXMediaGeneralMimeType)
       
   862         {
       
   863         if ( iMimeType.Des().Length() )
       
   864             {
       
   865             media->SetTextValueL(
       
   866                 TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralMimeType),
       
   867                 iMimeType.Des());
       
   868             }
       
   869 
       
   870         }
       
   871 
       
   872     // Set DRM info
       
   873     // Only try to get DRM info if the song has completed downloading
       
   874     if ( EPbDlStateDownloadCompleted == iDownloadState )
       
   875         {
       
   876         const CMPXMedia* drmMedia( iDrmMediaUtility->GetMediaL( attrD ));
       
   877         if ( drmMedia )
       
   878             {
       
   879             TInt count( drmMedia->Count() );
       
   880             for ( TInt i = 0; i < count; i++ )
       
   881                 {
       
   882                 TUint attrId( drmMedia->Attribute(i).AttributeId() );
       
   883                 if ( attrD & attrId )
       
   884                     {
       
   885                     TMPXAttribute mpxAtt( KMPXMediaIdDrm, attrId );
       
   886                     switch ( attrId )
       
   887                         {
       
   888                         case EMPXMediaDrmType:
       
   889                         case EMPXMediaDrmRightsStatus:
       
   890                         case EMPXMediaDrmRightsType:
       
   891                         case EMPXMediaDrmCount:
       
   892                             {
       
   893                             TInt val(
       
   894                                 *drmMedia->Value<TInt>( mpxAtt ));
       
   895                             media->SetTObjectValueL( mpxAtt, val );
       
   896                             break;
       
   897                             }
       
   898                         case EMPXMediaDrmProtected:
       
   899                         case EMPXMediaDrmSendingAllowed:
       
   900                         case EMPXMediaDrmCanSetAutomated:
       
   901                         case EMPXMediaDrmHasInfoUrl:
       
   902                         case EMPXMediaDrmHasPreviewUrl:
       
   903                         case EMPXMediaDrmAboutToExpire:
       
   904                             {
       
   905                             TBool val(
       
   906                                 *drmMedia->Value<TBool>( mpxAtt ));
       
   907                             media->SetTObjectValueL( mpxAtt, val );
       
   908                             break;
       
   909                             }
       
   910                         case EMPXMediaDrmStartTime:
       
   911                         case EMPXMediaDrmEndTime:
       
   912                         case EMPXMediaDrmIntervalStartTime:
       
   913                         case EMPXMediaDrmAccumulatedTime:
       
   914                             {
       
   915                             TInt64 val(
       
   916                                 *drmMedia->Value<TInt64>( mpxAtt ));
       
   917                             media->SetTObjectValueL( mpxAtt, val );
       
   918                             break;
       
   919                             }
       
   920                         case EMPXMediaDrmInterval:
       
   921                             {
       
   922                             TTimeIntervalSeconds val(
       
   923                                 *drmMedia->Value<TTimeIntervalSeconds>(mpxAtt));
       
   924                             media->SetTObjectValueL( mpxAtt, val );
       
   925                             break;
       
   926                             }
       
   927                         default:
       
   928                             {
       
   929                             break;
       
   930                             }
       
   931                         }   // end switch (attriId)
       
   932                     }   // end if ( attrD & attrId )
       
   933                 }
       
   934             }
       
   935         }
       
   936 
       
   937     iObs->HandleMedia(*media, KErrNone);
       
   938     CleanupStack::PopAndDestroy(media);
       
   939 
       
   940     MPX_DEBUG1("CMPXProgressDownloadSB::MediaL() exiting");
       
   941     }
       
   942 
       
   943 // ----------------------------------------------------------------------------
       
   944 // Cancel request
       
   945 // ----------------------------------------------------------------------------
       
   946 //
       
   947 void CMPXProgressDownloadSB::CancelRequest()
       
   948     {
       
   949     }
       
   950 
       
   951 
       
   952 // -----------------------------------------------------------------------------
       
   953 // CMPXProgressDownloadSB::Event
       
   954 // -----------------------------------------------------------------------------
       
   955 //
       
   956 void CMPXProgressDownloadSB::Event(
       
   957     MControl* aControl,
       
   958     TUint aEventType,
       
   959     TAny* aEventObject )
       
   960     {
       
   961 
       
   962     MPX_DEBUG1("CMPXProgressDownloadSB::Event() entering");
       
   963 
       
   964     if (( aControl == NULL) || (aEventObject == NULL ))
       
   965         {
       
   966         MPX_DEBUG3("CMPXProgressDownloadSB::Event() Error: aControl=%x aEventObject=%x", aControl, aEventObject);
       
   967         }
       
   968 
       
   969 
       
   970     switch ( aEventType )
       
   971         {
       
   972         case MStreamControlObserver::KStateChangedEvent:
       
   973             {
       
   974             MStreamControl* control1 = (MStreamControl*)(aControl);
       
   975             MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[%d]",control1->GetState());
       
   976 
       
   977             MStateChangedEvent* event = (MStateChangedEvent*)aEventObject;
       
   978             switch( event->GetState())
       
   979                 {
       
   980                 case MStreamControl::INITIALIZED:
       
   981                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[INITIALIZED]");
       
   982                     if( event->GetErrorCode() == KErrNone && iState == EStateInitialising )
       
   983                         {
       
   984                         delete iDrmCustomCommand;
       
   985                         iDrmCustomCommand = NULL;
       
   986                         iDrmCustomCommand = (RMMFDRMCustomCommands*)iMStreamControl->CustomInterface(KUidInterfaceMMFDRMControl);
       
   987 
       
   988                         if ( iDrmCustomCommand )
       
   989                             {
       
   990                             TInt drmCCErr = iDrmCustomCommand->DisableAutomaticIntent(ETrue);
       
   991                             // TODO:
       
   992                             // for wmdrm pdl, we need to let helix consume rights.
       
   993                             // by calling ExecuteIntent() when playback completes.
       
   994                             }
       
   995                         iState = EStateInitialised;
       
   996                         // Restore volume level
       
   997                         TInt currentVol( 0 );
       
   998                         MPX_TRAPD( volError, currentVol = iVolumeWatcher->CurrentValueL() );
       
   999                         if ( volError == KErrNone )
       
  1000                             {
       
  1001                             SetVolume( currentVol );
       
  1002                             TBool mute( EFalse);
       
  1003                             MPX_TRAPD( muteError, mute = iMuteWatcher->CurrentValueL() );
       
  1004                             if ( muteError == KErrNone && mute )
       
  1005                                 {
       
  1006                                 SetMute(mute);
       
  1007                                 }
       
  1008                             }
       
  1009                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPActive, ETrue, event->GetErrorCode());
       
  1010                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPaused, 0, event->GetErrorCode());
       
  1011                         }
       
  1012                     else if ( event->GetErrorCode() == KErrEof ) // Playback Complete
       
  1013                         {
       
  1014                         MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[PlaybackComplete] errorcode=%d",event->GetErrorCode());
       
  1015                         if ( iDownloadState == EPbDlStateDownloadCompleted && !iFileSaved )
       
  1016                             {
       
  1017                             if ( event->GetErrorCode() == KErrEof )
       
  1018                                 {
       
  1019                                 ConsumeRights( ContentAccess::EStop );
       
  1020                                 }
       
  1021                             else
       
  1022                                 {
       
  1023                                 ConsumeRights( ContentAccess::EPause );
       
  1024                                 }
       
  1025                             MoveDownloadedFileToMusicFolderL();
       
  1026                             }
       
  1027                         }
       
  1028                     else if ( event->GetErrorCode() == KErrDied || event->GetErrorCode() == KErrInUse ||
       
  1029                             event->GetErrorCode() == KErrAccessDenied )
       
  1030                         {
       
  1031                         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPaused,
       
  1032                                                  0, event->GetErrorCode() );
       
  1033                         }
       
  1034                     else
       
  1035                         {
       
  1036                         //Todo: Error cases such as no rights to play.
       
  1037                         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlayComplete, 0, event->GetErrorCode());
       
  1038                         }
       
  1039                     break;
       
  1040                 case MStreamControl::CLOSED:
       
  1041                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Closed]");
       
  1042            //         if ( iDownloadState == EPbDlStateDownloadCompleted )
       
  1043            //             {
       
  1044            //             MoveDownloadedFileToMusicFolderL();	//The file should be moved somewhere else.
       
  1045            //             }
       
  1046                     iErrorOfStreamClosedEvent = event->GetErrorCode();
       
  1047                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPClosed, 0, event->GetErrorCode() );
       
  1048                     break;
       
  1049                 case MStreamControl::PRIMED:
       
  1050                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Primed]");
       
  1051                     TInt64 duration;
       
  1052                     if (iMStreamControl->GetDuration(duration) != KErrUnknown )
       
  1053                         {
       
  1054                         MPX_DEBUG2("CMPXProgressDownloadSB::Event:KDurationChangedEvent Duration = %d", I64INT(duration));
       
  1055                         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDurationChanged, duration / KPbMilliMultiplier, KErrNone);
       
  1056                         }
       
  1057                     break;
       
  1058                 case MStreamControl::EXECUTING://Playing
       
  1059                     {
       
  1060                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Playing]");
       
  1061                     iStreamBuffering = EFalse;
       
  1062                     iPlaying = ETrue;
       
  1063                  // Send the Started-message here since View may not have been initialized earlier.
       
  1064                 	TUint expectedFileSize = 0;
       
  1065                 	iMAudioProgDLSource->GetExpectedFileSize(expectedFileSize);
       
  1066                 	iDownloadSize = expectedFileSize;
       
  1067                 	iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadStarted,
       
  1068                 	                         iDownloadSize,
       
  1069                 	                         KErrNone );
       
  1070 
       
  1071                     if ( iDownloadState == EPbDlStateBuffering )
       
  1072                         {
       
  1073                         iDownloadState = EPbDlStateDownloading;
       
  1074                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPDownloadStateChanged, iDownloadState, KErrNone);
       
  1075                         }
       
  1076                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPlaying, 0, event->GetErrorCode());
       
  1077                     TInt64 duration;
       
  1078                     if (iMStreamControl->GetDuration(duration) != KErrUnknown )
       
  1079                         {
       
  1080                         MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged Duration = %d", I64INT(duration));
       
  1081                         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDurationChanged, duration / KPbMilliMultiplier, KErrNone);
       
  1082                         }
       
  1083                     }
       
  1084                     break;
       
  1085                 case MStreamControl::BUFFERING:
       
  1086                     MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[Buffering] errorcode= %d",event->GetErrorCode());
       
  1087                     iStreamBuffering = ETrue;
       
  1088                     if ( iDownloadState != EPbDlStateDownloadPaused ||
       
  1089                          iDownloadState != EPbDlStateDownloadCanceled ||
       
  1090                          iDownloadState != EPbDlStateDownloadError ||
       
  1091                          iDownloadState != EPbDlStateNotDownloading
       
  1092                          )
       
  1093                         {
       
  1094                         iDownloadState = EPbDlStateBuffering;
       
  1095                         }
       
  1096                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPaused, 0, event->GetErrorCode());
       
  1097                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPDownloadStateChanged, iDownloadState, KErrNone);
       
  1098                     break;
       
  1099                 case MStreamControl::PAUSED:
       
  1100                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Paused]");
       
  1101                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPaused, 0, event->GetErrorCode());
       
  1102                     break;
       
  1103                 default:
       
  1104                     break;
       
  1105                 }
       
  1106             }
       
  1107             break;
       
  1108 
       
  1109         case MStreamControlObserver::KDurationChangedEvent:
       
  1110             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KDurationChangedEvent");
       
  1111             TInt64 duration;
       
  1112             if (iMStreamControl->GetDuration(duration) != KErrUnknown )
       
  1113                 {
       
  1114                 MPX_DEBUG2("CMPXProgressDownloadSB::Event:KDurationChangedEvent Duration = %d", I64INT(duration));
       
  1115                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDurationChanged, duration / KPbMilliMultiplier, KErrNone);
       
  1116                 }
       
  1117             break;
       
  1118 
       
  1119         case MSourceControlObserver::KDownloadStatusChangedEvent:
       
  1120             {
       
  1121             MProgDLSource* control1 = (MProgDLSource*)(aControl);
       
  1122             MPX_DEBUG2("CMPXProgressDownloadSB::Event:DownloadStatus[%d]",control1->GetDownloadStatus());
       
  1123             switch ( control1->GetDownloadStatus() )
       
  1124                 {
       
  1125 
       
  1126                 case MProgDLSource::EConnecting:
       
  1127                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:DownloadStatus [connecting]");
       
  1128                     break;
       
  1129 
       
  1130                 case MProgDLSource::EStarted:
       
  1131                     {
       
  1132                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:DownloadStatus [started]");
       
  1133                     iDownloadState = EPbDlStateDownloading;
       
  1134                     iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadStateChanged,
       
  1135                                              iDownloadState,
       
  1136                                              KErrNone);
       
  1137 
       
  1138                     TUint expectedFileSize = 0;
       
  1139                     iMAudioProgDLSource->GetExpectedFileSize(expectedFileSize);
       
  1140                     iDownloadSize = expectedFileSize;
       
  1141                     iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadStarted,
       
  1142                                              iDownloadSize,
       
  1143                                              KErrNone );
       
  1144                     }
       
  1145                     break;
       
  1146 
       
  1147                 case MProgDLSource::EPaused:
       
  1148                     {
       
  1149                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:DownloadStatus [paused]");
       
  1150                     iDownloadState = EPbDlStateDownloadPaused;
       
  1151                     iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadStateChanged,
       
  1152                                              iDownloadState,
       
  1153                                              KErrNone);
       
  1154 
       
  1155                     }
       
  1156                     break;
       
  1157 
       
  1158                 case MProgDLSource::EDeleted: 	//download has been canceled from Browser
       
  1159                     {							//or Browser has Exited
       
  1160                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:DownloadStatus [deleted]");
       
  1161 
       
  1162                     iMStreamControl->Stop();
       
  1163                     iMStreamControl->Close();
       
  1164                     iDrmMediaUtility->Close();
       
  1165                     //Stop the play
       
  1166                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPStopped,
       
  1167                                              0, KErrNone);
       
  1168                     iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlayComplete, 0, KErrNone);
       
  1169                     if (!iOngoingCmdCancelDownload) // when Dl was canceled by browser
       
  1170                         {
       
  1171                         iObs->HandlePluginEvent(
       
  1172                                 MMPXPlaybackPluginObserver::EPDownloadCmdCancelDownload,
       
  1173                                 iTransactionId,
       
  1174                                 KErrNone);
       
  1175                         }
       
  1176                     break;                    
       
  1177                     }
       
  1178                 case MProgDLSource::ECompleted:
       
  1179                     {
       
  1180                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:DownloadStatus [completed]");
       
  1181                     iDownloadState = EPbDlStateDownloadCompleted;
       
  1182 
       
  1183                     // and notify playback engine of the change.
       
  1184                     iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadPositionChanged,
       
  1185                                              iDownloadSize,
       
  1186                                              KErrNone);
       
  1187 
       
  1188                     if ((iState == EStateNotInitialised || 
       
  1189                         (iState == EStateInitialising && iErrorOfStreamClosedEvent == KErrCANoRights)) 
       
  1190                         && !iFileSaved )
       
  1191                          {
       
  1192                          MoveDownloadedFileToMusicFolderL();
       
  1193                          }
       
  1194                      iErrorOfStreamClosedEvent = KErrNone ;
       
  1195 
       
  1196 
       
  1197                     iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadStateChanged,
       
  1198                                              iDownloadState,
       
  1199                                              KErrNone);
       
  1200                     }
       
  1201                     break;
       
  1202                 case MProgDLSource::EFailed:
       
  1203                 case MProgDLSource::EUnknown:
       
  1204                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:DownloadStatus [failed]");
       
  1205                     iDownloadState = EPbDlStateDownloadError;
       
  1206                     iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadStateChanged,
       
  1207                                              iDownloadState,
       
  1208                                              KErrNone);
       
  1209                     break;
       
  1210                 default:
       
  1211                   break;
       
  1212                 }
       
  1213             }
       
  1214             break;
       
  1215 
       
  1216         case MSourceControlObserver::KFileMoveCompleteEvent:
       
  1217             {
       
  1218             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KFileMoveCompleteEvent");
       
  1219 
       
  1220             MErrorCode* errorObj = (MErrorCode*)aEventObject;
       
  1221             TInt fileMoveError = errorObj->GetErrorCode();
       
  1222 
       
  1223             if ( !fileMoveError )
       
  1224                 {
       
  1225                 delete iPdPath;
       
  1226                 iPdPath = NULL;
       
  1227                 iPdPath = iMovedFileName.AllocL();
       
  1228                 iFileSaved = ETrue;
       
  1229                 }
       
  1230             else
       
  1231                 {
       
  1232                 // TODO: If file is renamed, we need to get the new path.
       
  1233                 if( fileMoveError == KErrAlreadyExists )
       
  1234                     {
       
  1235                     TPtr ptr( NULL, 0 );
       
  1236                     iMAudioProgDLSource->FileName( ptr );
       
  1237                     delete iPdPath;
       
  1238                     iPdPath = NULL;
       
  1239                     iPdPath = ptr.AllocL();
       
  1240                     iFileSaved = ETrue;
       
  1241                     }
       
  1242                 }
       
  1243 
       
  1244             TRAP_IGNORE( iDrmMediaUtility->InitL( *iPdPath ));
       
  1245             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlayComplete, 0, KErrNone);
       
  1246 
       
  1247             if ( !fileMoveError || fileMoveError == KErrAlreadyExists )
       
  1248                 {
       
  1249                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadFileMoved, (TInt)iPdPath, KErrNone);
       
  1250                 }
       
  1251             break;
       
  1252             }
       
  1253         case MSourceControlObserver::KPercentageDownloadedChangedEvent:
       
  1254             {
       
  1255             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KPercentageDownloadedChangedEvent");
       
  1256 
       
  1257             if (iDownloadState == EPbDlStateDownloadPaused)
       
  1258                 {
       
  1259                 iDownloadState = EPbDlStateBuffering;
       
  1260                 }
       
  1261 
       
  1262             // update current file size
       
  1263             TUint currentFileSize = 0;
       
  1264             TUint expectedFileSize = 0;
       
  1265 
       
  1266             iMAudioProgDLSource->GetCurrentFileSize(currentFileSize);
       
  1267             iMAudioProgDLSource->GetExpectedFileSize(expectedFileSize);
       
  1268             iDownloadBytes = currentFileSize;
       
  1269             if (expectedFileSize != iDownloadSize)
       
  1270             	{
       
  1271                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadingUpdated,
       
  1272                                          expectedFileSize,
       
  1273                                          KErrNone);            	
       
  1274             	}
       
  1275             iDownloadSize = expectedFileSize;
       
  1276 
       
  1277             // and notify playback engine of the change.
       
  1278             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadPositionChanged,
       
  1279                                      iDownloadBytes,
       
  1280                                      KErrNone);
       
  1281 
       
  1282             }
       
  1283             break;
       
  1284 
       
  1285         default:
       
  1286             break;
       
  1287         }//end switch (aEventType)
       
  1288     MPX_DEBUG1("CMPXProgressDownloadSB::Event() exiting");
       
  1289     }
       
  1290 
       
  1291 // ----------------------------------------------------------------------------
       
  1292 // Handle a change in a setting value.
       
  1293 // ----------------------------------------------------------------------------
       
  1294 //
       
  1295 void CMPXProgressDownloadSB::HandleSettingChange(
       
  1296     const TUid& aRepositoryUid,
       
  1297     TUint32 aSettingId )
       
  1298     {
       
  1299     MPX_DEBUG1("CMPXProgressDownloadSB::HandleSettingChange() entering");
       
  1300 
       
  1301     if ( KCRUidMPXSettings == aRepositoryUid &&
       
  1302          KMPXPlaybackVolume == aSettingId )
       
  1303         {
       
  1304         MPX_DEBUG1("CMPXProgressDownloadSB::HandleSettingChange() Volume setting changed");
       
  1305         TInt vol( 0 );
       
  1306         MPX_TRAPD( error, vol = iVolumeWatcher->CurrentValueL() );
       
  1307         if ( error == KErrNone )
       
  1308             {
       
  1309             SetVolume( vol );
       
  1310             }
       
  1311         }
       
  1312     else if ( KCRUidMPXSettings == aRepositoryUid &&
       
  1313          KMPXPlaybackMute == aSettingId )
       
  1314         {
       
  1315         MPX_DEBUG1("CMPXProgressDownloadSB::HandleSettingChange() Mute setting changed");
       
  1316         TBool mute( EFalse );
       
  1317         MPX_TRAPD( error, mute = static_cast<TBool>(iMuteWatcher->CurrentValueL()) );
       
  1318         if ( error == KErrNone )
       
  1319             {
       
  1320             TInt oldVolume( 0 );
       
  1321             iMVolumeControl->GetVolume( oldVolume );
       
  1322             if ( (mute && oldVolume != 0) || (!mute && oldVolume == 0) )
       
  1323                 {
       
  1324                 SetMute( mute );
       
  1325                 }
       
  1326             }
       
  1327         }
       
  1328     MPX_DEBUG1("CMPXProgressDownloadSB::HandleSettingChange() exiting");
       
  1329     }
       
  1330 
       
  1331 // ----------------------------------------------------------------------------
       
  1332 // Sets the volume level in audio controller
       
  1333 // ----------------------------------------------------------------------------
       
  1334 //
       
  1335 void CMPXProgressDownloadSB::SetVolume( TInt aVolume )
       
  1336     {
       
  1337     MPX_DEBUG2("CMPXProgressDownloadSB::SetVolume(%d) entering", aVolume);
       
  1338 
       
  1339     // Ensure that level is within min and max values
       
  1340     if ( aVolume > KPbPlaybackVolumeLevelMax )
       
  1341         {
       
  1342         aVolume = KPbPlaybackVolumeLevelMax;
       
  1343         }
       
  1344     if ( aVolume < KPbPlaybackVolumeLevelMin )
       
  1345         {
       
  1346         aVolume = KPbPlaybackVolumeLevelMin;
       
  1347         }
       
  1348 
       
  1349     TBool changed( EFalse );
       
  1350     // Change MMF Audio player's volume
       
  1351     if ( EStateInitialised == iState )
       
  1352         {
       
  1353         TInt maxVolume(0);
       
  1354         iMVolumeControl->GetMaxVolume(maxVolume);
       
  1355         TInt newVolume( aVolume * maxVolume / 100 );
       
  1356         MPX_DEBUG2("CMPXProgressDownloadSB::SetVolume(): Setting volume = %d", newVolume);
       
  1357 
       
  1358         // First check if MMF Audio player's volume is changed by new value
       
  1359         TInt oldVolume( 0 );
       
  1360         iMVolumeControl->GetVolume( oldVolume );
       
  1361         if ( newVolume != oldVolume )
       
  1362             {
       
  1363             iMVolumeControl->SetVolume( newVolume );
       
  1364             iMVolumeControl->Apply();
       
  1365             changed = ETrue;
       
  1366             }
       
  1367         }
       
  1368 
       
  1369     // Change setting in cenrep
       
  1370     if ( aVolume != iVolumeWatcher->CurrentValueL() )
       
  1371         {
       
  1372         iVolumeWatcher->SetValueL( aVolume );
       
  1373         }
       
  1374 
       
  1375     // Notify observer if value changed
       
  1376     if ( changed )
       
  1377         {
       
  1378         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPVolumeChanged,
       
  1379                                  aVolume,
       
  1380                                  KErrNone);
       
  1381         }
       
  1382 
       
  1383     MPX_DEBUG1("CMPXProgressDownloadSB::SetVolume() exiting");
       
  1384     }
       
  1385 
       
  1386 // ----------------------------------------------------------------------------
       
  1387 // Sets the volume level in audio controller
       
  1388 // ----------------------------------------------------------------------------
       
  1389 //
       
  1390 void CMPXProgressDownloadSB::SetMute( TBool aMute )
       
  1391     {
       
  1392     MPX_DEBUG3("-->CMPXProgressDownloadSB::SetMute 0x%08x vol (%d)", this, aMute);
       
  1393 
       
  1394     TBool changed( EFalse );
       
  1395     // Change MMF Audio player's volume
       
  1396     TInt currentVolume(0);
       
  1397     iMVolumeControl->GetVolume(currentVolume);
       
  1398     if ( aMute && currentVolume != 0 )
       
  1399         {
       
  1400         iVolume = currentVolume;
       
  1401         TInt vol = 0;
       
  1402         iMVolumeControl->SetVolume(vol);
       
  1403         iMVolumeControl->Apply();
       
  1404         changed = ETrue;
       
  1405         }
       
  1406     else if ( !aMute && currentVolume == 0 )      // UnMute
       
  1407         {
       
  1408         iMVolumeControl->SetVolume(iVolume);
       
  1409         iMVolumeControl->Apply();
       
  1410         changed = ETrue;
       
  1411         }
       
  1412 
       
  1413     // Change setting in cenrep
       
  1414     TBool currentMute( EFalse );
       
  1415     MPX_TRAPD( muteError, currentMute = iMuteWatcher->CurrentValueL() );
       
  1416     if ( muteError == KErrNone )
       
  1417         {
       
  1418         if ( aMute && !currentMute )
       
  1419             {
       
  1420             MPX_TRAP( muteError, iMuteWatcher->SetValueL( aMute ) );
       
  1421             }
       
  1422         else if ( !aMute && currentMute )
       
  1423             {
       
  1424             MPX_TRAP( muteError, iMuteWatcher->SetValueL( aMute ) );
       
  1425             }
       
  1426         }
       
  1427 
       
  1428     // Notify observer if value changed
       
  1429     if ( changed )
       
  1430         {
       
  1431         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
       
  1432                                  aMute,
       
  1433                                  KErrNone);
       
  1434         }
       
  1435 
       
  1436     MPX_DEBUG3("<--CMPXProgressDownloadSB::SetMute 0x%08x vol (%d)", this, aMute);
       
  1437     }
       
  1438 
       
  1439 // -----------------------------------------------------------------------------
       
  1440 // CMPXProgressDownloadSB::MoveDownloadedFileToMusicFolderL
       
  1441 // -----------------------------------------------------------------------------
       
  1442 //
       
  1443 void CMPXProgressDownloadSB::MoveDownloadedFileToMusicFolderL()
       
  1444     {
       
  1445     if ( iFileSaved || ( (*iPdPath).Length() == 0 ) )
       
  1446         {
       
  1447         return;
       
  1448         }
       
  1449 
       
  1450     MPX_DEBUG1("CMPXProgressDownloadSB::MoveDownloadedFileToMusicFolderL() entering");
       
  1451     TParse parse;
       
  1452     parse.Set(*iPdPath,NULL,NULL);
       
  1453     TPtrC drive = parse.Drive();
       
  1454 
       
  1455     iMovedFileName.Copy(drive);
       
  1456     iMovedFileName.Append(_L("\\Data\\") );
       
  1457     iMovedFileName.Append(_L("Download\\") );
       
  1458     iFs.MkDirAll(iMovedFileName);
       
  1459     iMovedFileName.Append(parse.NameAndExt() );
       
  1460     TInt error = iMAudioProgDLSource->MoveFile(iMovedFileName);
       
  1461 
       
  1462     if ( !error )
       
  1463         {
       
  1464         iFileSaved = ETrue;
       
  1465         }
       
  1466 
       
  1467     MPX_DEBUG1("CMPXProgressDownloadSB::MoveDownloadedFileToMusicFolderL() exiting");
       
  1468     }
       
  1469 
       
  1470 // ----------------------------------------------------------------------------
       
  1471 // Consumes the rights for the current media
       
  1472 // ----------------------------------------------------------------------------
       
  1473 //
       
  1474 void CMPXProgressDownloadSB::ConsumeRights(
       
  1475     ContentAccess::TIntent aIntent )
       
  1476     {
       
  1477     MPX_DEBUG2("-->CMPXProgressDownloadSB::ConsumeRights(%d)", aIntent);
       
  1478     if ( iDrmCustomCommand )
       
  1479         {
       
  1480         switch ( aIntent )
       
  1481             {
       
  1482             case ContentAccess::EPlay:
       
  1483             case ContentAccess::EStop:
       
  1484             case ContentAccess::EPause:
       
  1485             case ContentAccess::EContinue:
       
  1486                 {
       
  1487                 break;
       
  1488                 }
       
  1489             default:
       
  1490                 {
       
  1491                 aIntent = ContentAccess::EUnknown;
       
  1492                 iConsumeStarted = EFalse;
       
  1493                 break;
       
  1494                 }
       
  1495             }
       
  1496         MPX_DEBUG2("-->CMPXProgressDownloadSB::ConsumeRights(): Executing intent %d", aIntent);
       
  1497         iDrmCustomCommand->ExecuteIntent(aIntent);
       
  1498         }
       
  1499     MPX_DEBUG2("<--CMPXProgressDownloadSB::ConsumeRights(%d)", aIntent);
       
  1500     }
       
  1501 
       
  1502 // End of file