mpxplugins/serviceplugins/playbackplugins/progressdownloadsb/src/mpxprogressdownloadsb.cpp
changeset 4 beaa16f65879
parent 2 b70d77332e66
child 10 c97423828d28
child 17 c8156a91d13c
equal deleted inserted replaced
3:3f752ecfeea4 4:beaa16f65879
   970     switch ( aEventType )
   970     switch ( aEventType )
   971         {
   971         {
   972         case MStreamControlObserver::KStateChangedEvent:
   972         case MStreamControlObserver::KStateChangedEvent:
   973             {
   973             {
   974             MStreamControl* control1 = (MStreamControl*)(aControl);
   974             MStreamControl* control1 = (MStreamControl*)(aControl);
   975             MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[%d]",control1->GetState());
   975             if(aEventObject && control1)
   976 
   976                 {
   977             MStateChangedEvent* event = (MStateChangedEvent*)aEventObject;
   977                 MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[%d]",control1->GetState());
   978             switch( event->GetState())
   978                 MStateChangedEvent* event = (MStateChangedEvent*)aEventObject;
   979                 {
   979                 switch(event->GetState())
   980                 case MStreamControl::INITIALIZED:
   980                     {
   981                     MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[INITIALIZED]");
   981                     case MStreamControl::INITIALIZED:
   982                     if( event->GetErrorCode() == KErrNone && iState == EStateInitialising )
   982                         MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[INITIALIZED]");
       
   983                         if( event->GetErrorCode() == KErrNone && iState == EStateInitialising )
       
   984                             {
       
   985                             delete iDrmCustomCommand;
       
   986                             iDrmCustomCommand = NULL;
       
   987                             iDrmCustomCommand = (RMMFDRMCustomCommands*)iMStreamControl->CustomInterface(KUidInterfaceMMFDRMControl);
       
   988 
       
   989                             if ( iDrmCustomCommand )
       
   990                                 {
       
   991                                 TInt drmCCErr = iDrmCustomCommand->DisableAutomaticIntent(ETrue);
       
   992                                 // TODO:
       
   993                                 // for wmdrm pdl, we need to let helix consume rights.
       
   994                                 // by calling ExecuteIntent() when playback completes.
       
   995                                 }
       
   996                             iState = EStateInitialised;
       
   997                             // Restore volume level
       
   998                             TInt currentVol( 0 );
       
   999                             MPX_TRAPD( volError, currentVol = iVolumeWatcher->CurrentValueL() );
       
  1000                             if ( volError == KErrNone )
       
  1001                                 {
       
  1002                                 SetVolume( currentVol );
       
  1003                                 TBool mute( EFalse);
       
  1004                                 MPX_TRAPD( muteError, mute = iMuteWatcher->CurrentValueL() );
       
  1005                                 if ( muteError == KErrNone && mute )
       
  1006                                     {
       
  1007                                     SetMute(mute);
       
  1008                                     }
       
  1009                                 }
       
  1010                             iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPActive, ETrue, event->GetErrorCode());
       
  1011                             iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPaused, 0, event->GetErrorCode());
       
  1012                             }
       
  1013                         else if ( event->GetErrorCode() == KErrEof ) // Playback Complete
       
  1014                             {
       
  1015                             MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[PlaybackComplete] errorcode=%d",event->GetErrorCode());
       
  1016                             if ( iDownloadState == EPbDlStateDownloadCompleted && !iFileSaved )
       
  1017                                 {
       
  1018                                 if ( event->GetErrorCode() == KErrEof )
       
  1019                                     {
       
  1020                                     ConsumeRights( ContentAccess::EStop );
       
  1021                                     }
       
  1022                                 else
       
  1023                                     {
       
  1024                                     ConsumeRights( ContentAccess::EPause );
       
  1025                                     }
       
  1026                                 MoveDownloadedFileToMusicFolderL();
       
  1027                                 }
       
  1028                             }
       
  1029                         else if ( event->GetErrorCode() == KErrDied || event->GetErrorCode() == KErrInUse ||
       
  1030                                 event->GetErrorCode() == KErrAccessDenied )
       
  1031                             {
       
  1032                             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPaused,
       
  1033                                     0, event->GetErrorCode() );
       
  1034                             }
       
  1035                         else
       
  1036                             {
       
  1037                             //Todo: Error cases such as no rights to play.
       
  1038                             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlayComplete, 0, event->GetErrorCode());
       
  1039                             }
       
  1040                         break;
       
  1041                     case MStreamControl::CLOSED:
       
  1042                         MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Closed]");
       
  1043                         //         if ( iDownloadState == EPbDlStateDownloadCompleted )
       
  1044                         //             {
       
  1045                         //             MoveDownloadedFileToMusicFolderL();	//The file should be moved somewhere else.
       
  1046                         //             }
       
  1047                         iErrorOfStreamClosedEvent = event->GetErrorCode();
       
  1048                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPClosed, 0, event->GetErrorCode() );
       
  1049                         break;
       
  1050                     case MStreamControl::PRIMED:
       
  1051                         MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Primed]");
       
  1052                         TInt64 duration;
       
  1053                         if (iMStreamControl->GetDuration(duration) != KErrUnknown )
       
  1054                             {
       
  1055                             MPX_DEBUG2("CMPXProgressDownloadSB::Event:KDurationChangedEvent Duration = %d", I64INT(duration));
       
  1056                             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDurationChanged, duration / KPbMilliMultiplier, KErrNone);
       
  1057                             }
       
  1058                         break;
       
  1059                     case MStreamControl::EXECUTING://Playing
   983                         {
  1060                         {
   984                         delete iDrmCustomCommand;
  1061                         MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Playing]");
   985                         iDrmCustomCommand = NULL;
  1062                         iStreamBuffering = EFalse;
   986                         iDrmCustomCommand = (RMMFDRMCustomCommands*)iMStreamControl->CustomInterface(KUidInterfaceMMFDRMControl);
  1063                         iPlaying = ETrue;
   987 
  1064                         // Send the Started-message here since View may not have been initialized earlier.
   988                         if ( iDrmCustomCommand )
  1065                         TUint expectedFileSize = 0;
   989                             {
  1066                         iMAudioProgDLSource->GetExpectedFileSize(expectedFileSize);
   990                             TInt drmCCErr = iDrmCustomCommand->DisableAutomaticIntent(ETrue);
  1067                         iDownloadSize = expectedFileSize;
   991                             // TODO:
  1068                         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadStarted,
   992                             // for wmdrm pdl, we need to let helix consume rights.
  1069                                 iDownloadSize,
   993                             // by calling ExecuteIntent() when playback completes.
  1070                                 KErrNone );
   994                             }
  1071 
   995                         iState = EStateInitialised;
  1072                         if ( iDownloadState == EPbDlStateBuffering )
   996                         // Restore volume level
  1073                             {
   997                         TInt currentVol( 0 );
  1074                             iDownloadState = EPbDlStateDownloading;
   998                         MPX_TRAPD( volError, currentVol = iVolumeWatcher->CurrentValueL() );
  1075                             iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPDownloadStateChanged, iDownloadState, KErrNone);
   999                         if ( volError == KErrNone )
  1076                             }
  1000                             {
  1077                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPlaying, 0, event->GetErrorCode());
  1001                             SetVolume( currentVol );
  1078                         TInt64 duration;
  1002                             TBool mute( EFalse);
  1079                         if (iMStreamControl->GetDuration(duration) != KErrUnknown )
  1003                             MPX_TRAPD( muteError, mute = iMuteWatcher->CurrentValueL() );
  1080                             {
  1004                             if ( muteError == KErrNone && mute )
  1081                             MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged Duration = %d", I64INT(duration));
  1005                                 {
  1082                             iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDurationChanged, duration / KPbMilliMultiplier, KErrNone);
  1006                                 SetMute(mute);
  1083                             }
  1007                                 }
  1084                         }
  1008                             }
  1085                         break;
  1009                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPActive, ETrue, event->GetErrorCode());
  1086                     case MStreamControl::BUFFERING:
       
  1087                         MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[Buffering] errorcode= %d",event->GetErrorCode());
       
  1088                         iStreamBuffering = ETrue;
       
  1089                         if ( iDownloadState != EPbDlStateDownloadPaused ||
       
  1090                                 iDownloadState != EPbDlStateDownloadCanceled ||
       
  1091                                 iDownloadState != EPbDlStateDownloadError ||
       
  1092                                 iDownloadState != EPbDlStateNotDownloading
       
  1093                         )
       
  1094                             {
       
  1095                             iDownloadState = EPbDlStateBuffering;
       
  1096                             }
  1010                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPaused, 0, event->GetErrorCode());
  1097                         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);
  1098                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPDownloadStateChanged, iDownloadState, KErrNone);
  1075                         }
  1099                         break;
  1076                     iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPlaying, 0, event->GetErrorCode());
  1100                     case MStreamControl::PAUSED:
  1077                     TInt64 duration;
  1101                         MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged[Paused]");
  1078                     if (iMStreamControl->GetDuration(duration) != KErrUnknown )
  1102                         iObs->HandlePluginEvent(MMPXPlaybackPluginObserver::EPPaused, 0, event->GetErrorCode());
  1079                         {
  1103                         break;
  1080                         MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged Duration = %d", I64INT(duration));
  1104                     default:
  1081                         iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDurationChanged, duration / KPbMilliMultiplier, KErrNone);
  1105                         break;
  1082                         }
       
  1083                     }
  1106                     }
  1084                     break;
  1107                 }
  1085                 case MStreamControl::BUFFERING:
  1108             else
  1086                     MPX_DEBUG2("CMPXProgressDownloadSB::Event:EStateChanged[Buffering] errorcode= %d",event->GetErrorCode());
  1109                 {
  1087                     iStreamBuffering = ETrue;
  1110                 MPX_DEBUG1("CMPXProgressDownloadSB::Event:EStateChanged aEventObject is KNullDesC");
  1088                     if ( iDownloadState != EPbDlStateDownloadPaused ||
  1111                 MPX_DEBUG1(" Code should not reach here as aEventObject is NULL");
  1089                          iDownloadState != EPbDlStateDownloadCanceled ||
  1112                 }      
  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             }
  1113             }
  1107             break;
  1114             break;
  1108 
  1115 
  1109         case MStreamControlObserver::KDurationChangedEvent:
  1116         case MStreamControlObserver::KDurationChangedEvent:
  1110             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KDurationChangedEvent");
  1117             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KDurationChangedEvent");
  1117             break;
  1124             break;
  1118 
  1125 
  1119         case MSourceControlObserver::KDownloadStatusChangedEvent:
  1126         case MSourceControlObserver::KDownloadStatusChangedEvent:
  1120             {
  1127             {
  1121             MProgDLSource* control1 = (MProgDLSource*)(aControl);
  1128             MProgDLSource* control1 = (MProgDLSource*)(aControl);
       
  1129             if( control1) 
       
  1130              {
  1122             MPX_DEBUG2("CMPXProgressDownloadSB::Event:DownloadStatus[%d]",control1->GetDownloadStatus());
  1131             MPX_DEBUG2("CMPXProgressDownloadSB::Event:DownloadStatus[%d]",control1->GetDownloadStatus());
  1123             switch ( control1->GetDownloadStatus() )
  1132             switch ( control1->GetDownloadStatus() )
  1124                 {
  1133                 {
  1125 
  1134 
  1126                 case MProgDLSource::EConnecting:
  1135                 case MProgDLSource::EConnecting:
  1208                                              KErrNone);
  1217                                              KErrNone);
  1209                     break;
  1218                     break;
  1210                 default:
  1219                 default:
  1211                   break;
  1220                   break;
  1212                 }
  1221                 }
       
  1222              }
       
  1223              else
       
  1224                 {
       
  1225                 MPX_DEBUG1("CMPXProgressDownloadSB::Event:DownloadStatus control1 is KNullDesC");
       
  1226 				MPX_DEBUG1("Code should not reach here, as control1 is NULL"); 
       
  1227                 }
  1213             }
  1228             }
  1214             break;
  1229             break;
  1215 
  1230 
  1216         case MSourceControlObserver::KFileMoveCompleteEvent:
  1231         case MSourceControlObserver::KFileMoveCompleteEvent:
  1217             {
  1232             {
  1218             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KFileMoveCompleteEvent");
  1233             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KFileMoveCompleteEvent");
  1219 
  1234             if( aEventObject)
       
  1235              {            
  1220             MErrorCode* errorObj = (MErrorCode*)aEventObject;
  1236             MErrorCode* errorObj = (MErrorCode*)aEventObject;
  1221             TInt fileMoveError = errorObj->GetErrorCode();
  1237             TInt fileMoveError = errorObj->GetErrorCode();
  1222 
  1238 
  1223             if ( !fileMoveError )
  1239             if ( !fileMoveError )
  1224                 {
  1240                 {
  1246 
  1262 
  1247             if ( !fileMoveError || fileMoveError == KErrAlreadyExists )
  1263             if ( !fileMoveError || fileMoveError == KErrAlreadyExists )
  1248                 {
  1264                 {
  1249                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadFileMoved, (TInt)iPdPath, KErrNone);
  1265                 iObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPDownloadFileMoved, (TInt)iPdPath, KErrNone);
  1250                 }
  1266                 }
       
  1267               }
       
  1268             else
       
  1269              {
       
  1270              	 MPX_DEBUG1("CMPXProgressDownloadSB::Event:KFileMoveCompleteEvent aEventObject is KNullDesC");
       
  1271                MPX_DEBUG1(" Code should not reach here as aEventObject is NULL");
       
  1272              }    
  1251             break;
  1273             break;
  1252             }
  1274             }
  1253         case MSourceControlObserver::KPercentageDownloadedChangedEvent:
  1275         case MSourceControlObserver::KPercentageDownloadedChangedEvent:
  1254             {
  1276             {
  1255             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KPercentageDownloadedChangedEvent");
  1277             MPX_DEBUG1("CMPXProgressDownloadSB::Event:KPercentageDownloadedChangedEvent");