videoplayback/videohelix/src/mpxvideoplaybackstate.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class plays local video file
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 30 %
       
    19 
       
    20 
       
    21 //
       
    22 //  INCLUDE FILES
       
    23 //
       
    24 #include <mpxcommandgeneraldefs.h>
       
    25 #include <mpxmessagegeneraldefs.h>
       
    26 
       
    27 #include "mpxvideoplaybackcontroller.h"
       
    28 #include "mpxvideoplaybackstate.h"
       
    29 #include <mpxvideoplaybackdefs.h>
       
    30 #include <mpxplaybackpluginobserver.h>
       
    31 #include <mpxmediageneraldefs.h>
       
    32 #include <mpxcenrepwatcher.h>
       
    33 
       
    34 #include <mmf/server/mmffile.h>
       
    35 #include <mmf/common/mmferrors.h>
       
    36 
       
    37 #include "mpxvideoseeker.h"
       
    38 #include "mpxvideoplayerutility.h"
       
    39 #include "mpxmediavideodefs.h"
       
    40 
       
    41 //
       
    42 //  CONSTANTS
       
    43 //
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===================================================
       
    46 
       
    47 //  ------------------------------------------------------------------------------------------------
       
    48 //    Symbian 2nd phase constructor can leave.
       
    49 //  ------------------------------------------------------------------------------------------------
       
    50 //
       
    51 void CMPXVideoPlaybackState::ConstructL( CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
    52 {
       
    53     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::ConstructL()"));
       
    54 
       
    55     iVideoPlaybackCtlr = aVideoPlaybackCtlr;
       
    56     iVideoPlaybackCtlr->iPBPluginError = KErrNone;
       
    57 
       
    58     User::LeaveIfError( iFs.Connect() );
       
    59     iFs.ShareProtected();
       
    60 }
       
    61 
       
    62 //  ------------------------------------------------------------------------------------------------
       
    63 //    C++ constructor
       
    64 //  ------------------------------------------------------------------------------------------------
       
    65 //
       
    66 CMPXVideoPlaybackState::CMPXVideoPlaybackState()
       
    67 {
       
    68 }
       
    69 
       
    70 //  ------------------------------------------------------------------------------------------------
       
    71 //    Destructor
       
    72 //  ------------------------------------------------------------------------------------------------
       
    73 //
       
    74 CMPXVideoPlaybackState::~CMPXVideoPlaybackState()
       
    75 {
       
    76     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::~CMPXVideoPlaybackState()"));
       
    77 
       
    78     iFs.Close();
       
    79 }
       
    80 
       
    81 //  ------------------------------------------------------------------------------------------------
       
    82 //    CMPXVideoPlaybackState::OpenFileL
       
    83 //  ------------------------------------------------------------------------------------------------
       
    84 void CMPXVideoPlaybackState::OpenFileL( const TDesC& /*aMediaFile*/ )
       
    85 {
       
    86     MPX_DEBUG(_L("CMPXVideoPlaybackState::OpenFileL()"));
       
    87 }
       
    88 
       
    89 //  ------------------------------------------------------------------------------------------------
       
    90 //    CMPXVideoPlaybackState::OpenFileL
       
    91 //  ------------------------------------------------------------------------------------------------
       
    92 void CMPXVideoPlaybackState::OpenFileL( const RFile& /*aMediaFile*/ )
       
    93 {
       
    94     MPX_DEBUG(_L("CMPXVideoPlaybackState::OpenFileL()"));
       
    95 }
       
    96 
       
    97 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
    98 
       
    99 //  ------------------------------------------------------------------------------------------------
       
   100 //    CMPXVideoPlaybackState::OpenFile64L
       
   101 //  ------------------------------------------------------------------------------------------------
       
   102 void CMPXVideoPlaybackState::OpenFile64L( const RFile64& /*aMediaFile*/ )
       
   103 {
       
   104     MPX_DEBUG(_L("CMPXVideoPlaybackState::OpenFile64L( RFile64 )"));
       
   105 }
       
   106 
       
   107 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   108 
       
   109 //  ------------------------------------------------------------------------------------------------
       
   110 //    CMPXVideoPlaybackState::HandlePlay()
       
   111 //  ------------------------------------------------------------------------------------------------
       
   112 void CMPXVideoPlaybackState::HandlePlay()
       
   113 {
       
   114     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePlay()"));
       
   115 }
       
   116 
       
   117 //  ------------------------------------------------------------------------------------------------
       
   118 //    CMPXVideoPlaybackState::HandlePause()
       
   119 //
       
   120 //   @@FP for now we are assuming that Pause is only valid for Playing state
       
   121 //  ------------------------------------------------------------------------------------------------
       
   122 void CMPXVideoPlaybackState::HandlePause()
       
   123 {
       
   124     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePause()"));
       
   125 }
       
   126 
       
   127 //  ------------------------------------------------------------------------------------------------
       
   128 //    CMPXVideoPlaybackState::HandlePlayPause()
       
   129 //
       
   130 //  ------------------------------------------------------------------------------------------------
       
   131 void CMPXVideoPlaybackState::HandlePlayPause()
       
   132 {
       
   133     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePlayPause()"));
       
   134 }
       
   135 
       
   136 //  ------------------------------------------------------------------------------------------------
       
   137 //    CMPXVideoPlaybackState::HandleStop()
       
   138 //  ------------------------------------------------------------------------------------------------
       
   139 void CMPXVideoPlaybackState::HandleStop()
       
   140 {
       
   141     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandleStop()"));
       
   142 }
       
   143 
       
   144 //  ------------------------------------------------------------------------------------------------
       
   145 //  CMPXVideoPlaybackState::HandleClose
       
   146 //  ------------------------------------------------------------------------------------------------
       
   147 void CMPXVideoPlaybackState::HandleClose()
       
   148 {
       
   149     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandleClose()"));
       
   150 
       
   151     iVideoPlaybackCtlr->iPlayer->Stop();
       
   152 
       
   153     iVideoPlaybackCtlr->CloseController();
       
   154 
       
   155     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPClosed,
       
   156                                                           0,
       
   157                                                           KErrNone );
       
   158 }
       
   159 
       
   160 //  ------------------------------------------------------------------------------------------------
       
   161 //    CMPXVideoPlaybackState::HandleStartSeekL()
       
   162 //  ------------------------------------------------------------------------------------------------
       
   163 void CMPXVideoPlaybackState::HandleStartSeekL( TBool /*aForward*/ )
       
   164 {
       
   165     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleStartSeekL()"));
       
   166 }
       
   167 
       
   168 //  ------------------------------------------------------------------------------------------------
       
   169 //    CMPXVideoPlaybackState::HandleStopSeekL()
       
   170 //  ------------------------------------------------------------------------------------------------
       
   171 void CMPXVideoPlaybackState::HandleStopSeekL()
       
   172 {
       
   173     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleStopSeekL()"));
       
   174 }
       
   175 
       
   176 //  ------------------------------------------------------------------------------------------------
       
   177 //    CMPXVideoPlaybackState::HandleForeground()
       
   178 //  ------------------------------------------------------------------------------------------------
       
   179 void CMPXVideoPlaybackState::HandleForeground()
       
   180 {
       
   181     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleForeground()"));
       
   182 }
       
   183 
       
   184 //  ------------------------------------------------------------------------------------------------
       
   185 //    CMPXVideoPlaybackState::HandleBackground()
       
   186 //  ------------------------------------------------------------------------------------------------
       
   187 void CMPXVideoPlaybackState::HandleBackground()
       
   188 {
       
   189     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandleBackground()"));
       
   190 
       
   191     // Just pause the plackback
       
   192     HandlePause();
       
   193 }
       
   194 
       
   195 //  ------------------------------------------------------------------------------------------------
       
   196 //    CMPXVideoPlaybackState::HandleOpenComplete()
       
   197 //  ------------------------------------------------------------------------------------------------
       
   198 void CMPXVideoPlaybackState::HandleOpenComplete( TInt /*aError*/ )
       
   199 {
       
   200     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleOpenComplete()"));
       
   201 }
       
   202 
       
   203 
       
   204 //  ------------------------------------------------------------------------------------------------
       
   205 //    CMPXVideoPlaybackState::HandlePrepareComplete()
       
   206 //  ------------------------------------------------------------------------------------------------
       
   207 void CMPXVideoPlaybackState::HandlePrepareComplete(TInt /*aError*/)
       
   208 {
       
   209     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandlePrepareComplete()"));
       
   210 }
       
   211 
       
   212 //  ------------------------------------------------------------------------------------------------
       
   213 //    CMPXVideoPlaybackState::HandleLoadingStarted()
       
   214 //  ------------------------------------------------------------------------------------------------
       
   215 void CMPXVideoPlaybackState::HandleLoadingStarted()
       
   216 {
       
   217     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleLoadingStarted()"));
       
   218 }
       
   219 
       
   220 //  ------------------------------------------------------------------------------------------------
       
   221 //    CMPXVideoPlaybackState::HandleLoadingComplete()
       
   222 //  ------------------------------------------------------------------------------------------------
       
   223 void CMPXVideoPlaybackState::HandleLoadingComplete(TInt /*aError*/)
       
   224 {
       
   225     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleLoadingComplete()"));
       
   226 }
       
   227 
       
   228 //  ------------------------------------------------------------------------------------------------
       
   229 //    CMPXVideoPlaybackState::HandlePlaybackComplete()
       
   230 //  ------------------------------------------------------------------------------------------------
       
   231 //
       
   232 void CMPXVideoPlaybackState::HandlePlaybackComplete( TInt aError )
       
   233 {
       
   234     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandlePlaybackComplete()"),
       
   235                    _L("error = %d"), aError );
       
   236 
       
   237     if ( aError == KErrNone )
       
   238     {
       
   239         iVideoPlaybackCtlr->ChangeState( EMPXVideoStopped );
       
   240 
       
   241         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent(
       
   242             MMPXPlaybackPluginObserver::EPPlayComplete,
       
   243             0,
       
   244             aError );
       
   245     }
       
   246     else
       
   247     {
       
   248         //
       
   249         //  Notify the view of an error
       
   250         //
       
   251         MPX_TRAPD( err, SendErrorToViewL( aError ) );
       
   252     }
       
   253 }
       
   254 
       
   255 //  ----------------------------------------------------------------------------
       
   256 //    CMPXVideoPlaybackState::HandleEndOfClip()
       
   257 //  ----------------------------------------------------------------------------
       
   258 void CMPXVideoPlaybackState::HandleEndOfClip()
       
   259 {
       
   260     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandleEndOfClip()"));
       
   261 
       
   262     // Stop the player
       
   263     iVideoPlaybackCtlr->iPlayer->Stop();
       
   264 
       
   265     iVideoPlaybackCtlr->ChangeState( EMPXVideoStopped );
       
   266 
       
   267     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent(
       
   268         MMPXPlaybackPluginObserver::EPPlayComplete,
       
   269         0,
       
   270         KErrNone );
       
   271 }
       
   272 
       
   273 //  ------------------------------------------------------------------------------------------------
       
   274 //    CMPXVideoPlaybackState::HandleVolumeChange()
       
   275 //  ------------------------------------------------------------------------------------------------
       
   276 void CMPXVideoPlaybackState::HandleVolumeChange()
       
   277 {
       
   278     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleVolumeChange()"));
       
   279 
       
   280     MPX_TRAPD(err, iVideoPlaybackCtlr->SetVolumeMMFL());
       
   281 }
       
   282 
       
   283 //  ------------------------------------------------------------------------------------------------
       
   284 //    CMPXVideoPlaybackState::HandleSetPositionL()
       
   285 //  ------------------------------------------------------------------------------------------------
       
   286 void CMPXVideoPlaybackState::HandleSetPositionL(TInt /*aValue*/)
       
   287 {
       
   288     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleSetPositionL()"));
       
   289 }
       
   290 
       
   291 //  ------------------------------------------------------------------------------------------------
       
   292 //    CMPXVideoPlaybackState::RetrieveFileDetailsL
       
   293 //  ------------------------------------------------------------------------------------------------
       
   294 TInt CMPXVideoPlaybackState::RetrieveFileDetailsL( const TArray<TMPXAttribute>& aAttrs,
       
   295                                                    CMPXMedia* aMedia )
       
   296 {
       
   297     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::RetrieveFileDetailsL()"));
       
   298 
       
   299     TUint attrG(0);  //  General attributes
       
   300     TUint attrV(0);  //  Video attributes
       
   301 
       
   302     if (iVideoPlaybackCtlr->iPBPluginError != KErrNone)
       
   303     {
       
   304         aMedia->SetTObjectValueL<TInt>(
       
   305             TMPXAttribute( KMPXMediaVideoError ), iVideoPlaybackCtlr->iPBPluginError );
       
   306 
       
   307         iVideoPlaybackCtlr->iPBPluginError = KErrNone;
       
   308     }
       
   309     else
       
   310     {
       
   311         for ( TInt i = 0 ; i < aAttrs.Count() ; ++i )
       
   312         {
       
   313             TMPXAttribute attr( aAttrs[i] );
       
   314 
       
   315             if ( attr.ContentId() == KMPXMediaIdGeneral )
       
   316             {
       
   317                 attrG |= attr.AttributeId();
       
   318             }
       
   319             else if ( attr.ContentId() == KMPXMediaIdVideo )
       
   320             {
       
   321                 attrV |= attr.AttributeId();
       
   322             }
       
   323         }
       
   324 
       
   325         RetrieveGeneralAttributesL( aMedia, attrG );
       
   326         RetrieveVideoAttributesL( aMedia, attrV );
       
   327     }
       
   328 
       
   329     return KErrNone;
       
   330 }
       
   331 
       
   332 //  ------------------------------------------------------------------------------------------------
       
   333 //    CMPXVideoPlaybackState::RetrieveGeneralAttributesL
       
   334 //  ------------------------------------------------------------------------------------------------
       
   335 //
       
   336 void CMPXVideoPlaybackState::RetrieveGeneralAttributesL(  CMPXMedia* aMedia, TUint attrG  )
       
   337 {
       
   338     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::RetrieveGeneralAttributesL()"));
       
   339 
       
   340     //
       
   341     //  Clip name include path excluding scheme
       
   342     //
       
   343     if ( attrG & EMPXMediaGeneralUri )
       
   344     {
       
   345         aMedia->SetTextValueL(
       
   346             TMPXAttribute( KMPXMediaIdGeneral, EMPXMediaGeneralUri ),
       
   347             *( iVideoPlaybackCtlr->iFileDetails->iClipName ) );
       
   348     }
       
   349 
       
   350     //
       
   351     //  Duration
       
   352     //
       
   353     if ( attrG & EMPXMediaGeneralDuration )
       
   354     {
       
   355         aMedia->SetTObjectValueL<TInt>(
       
   356             TMPXAttribute( KMPXMediaIdGeneral, EMPXMediaGeneralDuration ),
       
   357             iVideoPlaybackCtlr->iFileDetails->iDuration.Int64() / KPbMilliMultiplier);
       
   358     }
       
   359 
       
   360     //
       
   361     //  Title
       
   362     //
       
   363     if ( ( attrG & EMPXMediaGeneralTitle ) && iVideoPlaybackCtlr->iFileDetails->iTitle )
       
   364     {
       
   365         aMedia->SetTextValueL(
       
   366             TMPXAttribute( KMPXMediaIdGeneral, EMPXMediaGeneralTitle ),
       
   367             *( iVideoPlaybackCtlr->iFileDetails->iTitle ) );
       
   368     }
       
   369 
       
   370     //
       
   371     //  Mime Type
       
   372     //
       
   373     if ( ( attrG & EMPXMediaGeneralMimeType ) && iVideoPlaybackCtlr->iFileDetails->iMimeType )
       
   374     {
       
   375          aMedia->SetTextValueL(
       
   376              TMPXAttribute( KMPXMediaIdGeneral, EMPXMediaGeneralMimeType ),
       
   377              *( iVideoPlaybackCtlr->iFileDetails->iMimeType ) );
       
   378     }
       
   379 }
       
   380 
       
   381 //  ------------------------------------------------------------------------------------------------
       
   382 //    CMPXVideoPlaybackState::RetrieveVideoAttributesL
       
   383 //  ------------------------------------------------------------------------------------------------
       
   384 //
       
   385 void CMPXVideoPlaybackState::RetrieveVideoAttributesL(  CMPXMedia* aMedia, TUint attrV  )
       
   386 {
       
   387     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::RetrieveVideoAttributesL()"));
       
   388 
       
   389     //
       
   390     //  Artist
       
   391     //
       
   392     if ( ( attrV & KMPXMediaVideoArtist.iAttributeId ) &&
       
   393          ( iVideoPlaybackCtlr->iFileDetails->iArtist ) )
       
   394     {
       
   395         aMedia->SetTextValueL(
       
   396             TMPXAttribute( KMPXMediaVideoArtist ),
       
   397             *( iVideoPlaybackCtlr->iFileDetails->iArtist ) );
       
   398     }
       
   399 
       
   400     //
       
   401     //  Partial Playback
       
   402     //
       
   403     if ( attrV & KMPXMediaVideoPartialPlayback.iAttributeId )
       
   404     {
       
   405         aMedia->SetTObjectValueL<TInt>(
       
   406             TMPXAttribute( KMPXMediaVideoPartialPlayback ),
       
   407             iVideoPlaybackCtlr->iFileDetails->iPartialPlayback );
       
   408     }
       
   409 
       
   410     //
       
   411     //  Audio Enabled
       
   412     //
       
   413     if ( attrV & KMPXMediaVideoAudioEnabled.iAttributeId )
       
   414     {
       
   415         aMedia->SetTObjectValueL<TInt>(
       
   416             TMPXAttribute( KMPXMediaVideoAudioEnabled ),
       
   417             iVideoPlaybackCtlr->iFileDetails->iAudioEnabled );
       
   418     }
       
   419 
       
   420     //
       
   421     //  Video Enabled
       
   422     //
       
   423     if ( attrV & KMPXMediaVideoVideoEnabled.iAttributeId )
       
   424     {
       
   425         aMedia->SetTObjectValueL<TInt>(
       
   426             TMPXAttribute( KMPXMediaVideoVideoEnabled ),
       
   427             iVideoPlaybackCtlr->iFileDetails->iVideoEnabled );
       
   428     }
       
   429 
       
   430     //
       
   431     //  Playback Mode
       
   432     //
       
   433     if ( attrV & KMPXMediaVideoPlaybackMode.iAttributeId )
       
   434     {
       
   435         aMedia->SetTObjectValueL<TInt>(
       
   436             TMPXAttribute( KMPXMediaVideoPlaybackMode ),
       
   437             iVideoPlaybackCtlr->iPlaybackMode->GetMode() );
       
   438     }
       
   439 
       
   440     //
       
   441     //  Seekable
       
   442     //
       
   443     if ( attrV & KMPXMediaVideoSeekable.iAttributeId )
       
   444     {
       
   445         aMedia->SetTObjectValueL<TBool>(
       
   446             TMPXAttribute( KMPXMediaVideoSeekable ),
       
   447             iVideoPlaybackCtlr->iFileDetails->iSeekable );
       
   448     }
       
   449 
       
   450     //
       
   451     //  Pausable
       
   452     //
       
   453     if ( attrV & KMPXMediaVideoPausableStream.iAttributeId )
       
   454     {
       
   455         aMedia->SetTObjectValueL<TBool>(
       
   456             TMPXAttribute( KMPXMediaVideoPausableStream ),
       
   457             iVideoPlaybackCtlr->iFileDetails->iPausableStream );
       
   458     }
       
   459 
       
   460     //
       
   461     //  Video Height
       
   462     //
       
   463     if ( attrV & KMPXMediaVideoHeight.iAttributeId )
       
   464     {
       
   465         aMedia->SetTObjectValueL<TInt>(
       
   466             TMPXAttribute( KMPXMediaVideoHeight ),
       
   467             iVideoPlaybackCtlr->iFileDetails->iResolutionHeight );
       
   468     }
       
   469 
       
   470     //
       
   471     //  Video Width
       
   472     //
       
   473     if ( attrV & KMPXMediaVideoWidth.iAttributeId )
       
   474     {
       
   475         aMedia->SetTObjectValueL<TInt>(
       
   476             TMPXAttribute( KMPXMediaVideoWidth ),
       
   477             iVideoPlaybackCtlr->iFileDetails->iResolutionWidth );
       
   478     }
       
   479 
       
   480     //
       
   481     //  TV-Out Connected
       
   482     //
       
   483     if ( attrV & KMPXMediaVideoTvOutConnected.iAttributeId )
       
   484     {
       
   485         aMedia->SetTObjectValueL<TInt>(
       
   486             TMPXAttribute( KMPXMediaVideoTvOutConnected ),
       
   487             iVideoPlaybackCtlr->iAccessoryMonitor->IsTvOutConnected() );
       
   488     }
       
   489 
       
   490     //
       
   491     //  TV-Out Playback Allowed
       
   492     //
       
   493     if ( attrV & KMPXMediaVideoTvOutPlayAllowed.iAttributeId )
       
   494     {
       
   495         aMedia->SetTObjectValueL<TInt>(
       
   496             TMPXAttribute( KMPXMediaVideoTvOutPlayAllowed ),
       
   497             iVideoPlaybackCtlr->iAccessoryMonitor->IsTvOutPlaybackAllowed() );
       
   498     }
       
   499 
       
   500     //
       
   501     //  BitRate
       
   502     //
       
   503     if ( attrV & KMPXMediaVideoBitRate.iAttributeId )
       
   504     {
       
   505         aMedia->SetTObjectValueL<TInt>(
       
   506             TMPXAttribute( KMPXMediaVideoBitRate ),
       
   507             iVideoPlaybackCtlr->iFileDetails->iBitRate );
       
   508     }
       
   509 
       
   510     //
       
   511     //  FourCC Code
       
   512     //
       
   513     if ( attrV & KMPXMediaFourCCCode.iAttributeId )
       
   514     {
       
   515         aMedia->SetTObjectValueL<TUint32>(
       
   516             TMPXAttribute( KMPXMediaFourCCCode ),
       
   517             iVideoPlaybackCtlr->iFileDetails->iFourCCCode );
       
   518     }
       
   519 
       
   520     //
       
   521     //  Drm Protected
       
   522     //
       
   523     if ( attrV & KMPXMediaVideoDrmProtected.iAttributeId )
       
   524     {
       
   525         aMedia->SetTObjectValueL<TInt>(
       
   526             TMPXAttribute( KMPXMediaVideoDrmProtected ),
       
   527             iVideoPlaybackCtlr->iFileDetails->iDrmProtected );
       
   528     }
       
   529 }
       
   530 
       
   531 //  ------------------------------------------------------------------------------------------------
       
   532 //    CMPXVideoPlaybackState::SendErrorToViewL
       
   533 //  ------------------------------------------------------------------------------------------------
       
   534 //
       
   535 void CMPXVideoPlaybackState::SendErrorToViewL( TInt aError )
       
   536 {
       
   537     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::SendErrorToViewL()"),
       
   538                    _L("aError = %d"), aError );
       
   539 
       
   540     //
       
   541     //  create command to pass to playback plugin
       
   542     //
       
   543     CMPXMessage* message = CMPXMessage::NewL();
       
   544     CleanupStack::PushL( message );
       
   545 
       
   546     message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMediaIdVideoPlayback );
       
   547 
       
   548     message->SetTObjectValueL<TMPXVideoPlaybackCommand>
       
   549         ( KMPXMediaVideoPlaybackCommand, EPbCmdPluginError );
       
   550 
       
   551     message->SetTObjectValueL<TInt>( KMPXMediaVideoError, aError );
       
   552 
       
   553     iVideoPlaybackCtlr->iMPXPluginObs->HandlePlaybackMessage( message, KErrNone );
       
   554 
       
   555     CleanupStack::PopAndDestroy( message );
       
   556 }
       
   557 
       
   558 // -------------------------------------------------------------------------------------------------
       
   559 //   CMPXVideoPlaybackController::HandleUnexpectedError
       
   560 // -------------------------------------------------------------------------------------------------
       
   561 //
       
   562 void CMPXVideoPlaybackState::HandleUnexpectedError( TInt aError )
       
   563 {
       
   564     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::HandleUnexpectedError()"),
       
   565                    _L("aError = %d"), aError );
       
   566 
       
   567     MPX_TRAPD( err, SendErrorToViewL( aError ) );
       
   568 }
       
   569 
       
   570 // -------------------------------------------------------------------------------------------------
       
   571 // CMPXVideoPlaybackController::ResolveTimeoutError
       
   572 // -------------------------------------------------------------------------------------------------
       
   573 //
       
   574 void CMPXVideoPlaybackState::ResolveTimeoutError(TInt aError)
       
   575 {
       
   576     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::ResolveTimeoutError()"),
       
   577                    _L("aError = %d"), aError );
       
   578 
       
   579     MPX_TRAPD( err, SendErrorToViewL( aError ) );
       
   580 }
       
   581 
       
   582 // -------------------------------------------------------------------------------------------------
       
   583 // CMPXVideoPlaybackState::SetAspectRatioL
       
   584 // -------------------------------------------------------------------------------------------------
       
   585 //
       
   586 void CMPXVideoPlaybackState::SetAspectRatioL( CMPXCommand& aCmd, TMMFScalingType aType )
       
   587 {
       
   588     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::SetAspectRatioL()"),
       
   589                    _L("aType = %d"), aType);
       
   590 
       
   591     TMMFMessageDestinationPckg destinationPckg( KUidInterfaceMMFControllerScalingMsg );
       
   592 
       
   593     TPckgBuf<TInt> scaleTypePckg( aType );
       
   594 
       
   595     TInt err =
       
   596         iVideoPlaybackCtlr->iPlayer->CustomCommandSync( destinationPckg,
       
   597                                                         EMMFSetScalingType,
       
   598                                                         scaleTypePckg,
       
   599                                                         KNullDesC8 );
       
   600 
       
   601     if ( err )
       
   602     {
       
   603         MPX_DEBUG(_L("CMPXVideoPlaybackState::SetAspectRatioL FAIL [%d]"), err);
       
   604     }
       
   605     else
       
   606     {
       
   607         iVideoPlaybackCtlr->iPlayer->RefreshFrameL();
       
   608 
       
   609     }
       
   610 
       
   611     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoAspectRatio, aType );
       
   612 }
       
   613 
       
   614 //  ------------------------------------------------------------------------------------------------
       
   615 //    CMPXVideoPlaybackState::CommandHandleBackground
       
   616 //  ------------------------------------------------------------------------------------------------
       
   617 void  CMPXVideoPlaybackState::CommandHandleBackground()
       
   618 {
       
   619     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::CommandHandleBackground()"));
       
   620 
       
   621     if ( !iVideoPlaybackCtlr->iAppInForeground ||
       
   622          iVideoPlaybackCtlr->IsAlarm() ||
       
   623          iVideoPlaybackCtlr->IsPhoneCall() ||
       
   624          iVideoPlaybackCtlr->IsVideoCall() )
       
   625     {
       
   626         iVideoPlaybackCtlr->iAllowAutoPlay = EFalse;
       
   627     }
       
   628 }
       
   629 
       
   630 //  ------------------------------------------------------------------------------------------------
       
   631 //    CMPXVideoPlaybackState::CommandHandleForeground
       
   632 //  ------------------------------------------------------------------------------------------------
       
   633 void  CMPXVideoPlaybackState::CommandHandleForeground()
       
   634 {
       
   635     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackState::CommandHandleForeground()"));
       
   636 
       
   637     if ( !iVideoPlaybackCtlr->IsActivePhoneCall() )
       
   638     {
       
   639         iVideoPlaybackCtlr->iAllowAutoPlay = ETrue;
       
   640     }
       
   641 }
       
   642 
       
   643 //  ------------------------------------------------------------------------------------------------
       
   644 //    CMPXVideoPlaybackState::HandleCustomPause()
       
   645 //  ------------------------------------------------------------------------------------------------
       
   646 void CMPXVideoPlaybackState::HandleCustomPause()
       
   647 {
       
   648     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleCustomPause()"));
       
   649 }
       
   650 
       
   651 //  ------------------------------------------------------------------------------------------------
       
   652 //    CMPXVideoPlaybackState::HandleCustomPlay()
       
   653 //  ------------------------------------------------------------------------------------------------
       
   654 void CMPXVideoPlaybackState::HandleCustomPlay()
       
   655 {
       
   656     MPX_DEBUG(_L("CMPXVideoPlaybackState::HandleCustomPlay()"));
       
   657 }
       
   658 
       
   659 //  ------------------------------------------------------------------------------------------------
       
   660 //    CMPXVideoPlaybackState::RetrieveBufferingPercentage()
       
   661 //  ------------------------------------------------------------------------------------------------
       
   662 TInt CMPXVideoPlaybackState::RetrieveBufferingPercentage()
       
   663 {
       
   664     MPX_DEBUG(_L("CMPXVideoPlaybackState::RetrieveBufferingPercentage()"));
       
   665     return 100;
       
   666 }
       
   667 
       
   668 // *************************************************************************************************
       
   669 //
       
   670 //                          STATE SUB-CLASSES
       
   671 //
       
   672 // *************************************************************************************************
       
   673 
       
   674 
       
   675 
       
   676 // *************************************************************************************************
       
   677 //
       
   678 //                       CMPXNotInitialisedState
       
   679 //
       
   680 // *************************************************************************************************
       
   681 
       
   682 //  ------------------------------------------------------------------------------------------------
       
   683 //  CMPXNotInitialisedState::NewL()
       
   684 //  ------------------------------------------------------------------------------------------------
       
   685 CMPXVideoPlaybackState* CMPXNotInitialisedState::NewL(
       
   686         CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
   687 {
       
   688     MPX_ENTER_EXIT(_L("CMPXNotInitialisedState::NewL()"));
       
   689 
       
   690     CMPXNotInitialisedState* self = new( ELeave ) CMPXNotInitialisedState();
       
   691     CleanupStack::PushL( self );
       
   692     self->ConstructL(aVideoPlaybackCtlr);
       
   693     CleanupStack::Pop();
       
   694     return self;
       
   695 }
       
   696 
       
   697 //  ------------------------------------------------------------------------------------------------
       
   698 //  CMPXNotInitialisedState::~CMPXNotInitialisedState()
       
   699 //  ------------------------------------------------------------------------------------------------
       
   700 CMPXNotInitialisedState::~CMPXNotInitialisedState()
       
   701 {
       
   702     MPX_DEBUG(_L("CMPXNotInitialisedState::~CMPXNotInitialisedState()"));
       
   703 }
       
   704 
       
   705 //  ------------------------------------------------------------------------------------------------
       
   706 //  CMPXNotInitialisedState::HandleVolumeChange
       
   707 //  ------------------------------------------------------------------------------------------------
       
   708 void CMPXNotInitialisedState::HandleVolumeChange()
       
   709 {
       
   710     MPX_DEBUG(_L("CMPXNotInitialisedState::HandleVolumeChange()"));
       
   711 }
       
   712 
       
   713 //  ------------------------------------------------------------------------------------------------
       
   714 //  CMPXNotInitialisedState::RetrieveFileDetailsL
       
   715 //  ------------------------------------------------------------------------------------------------
       
   716 TInt CMPXNotInitialisedState::RetrieveFileDetailsL( const TArray<TMPXAttribute>& /*aAttrs*/,
       
   717                                                     CMPXMedia* aMedia )
       
   718 {
       
   719     MPX_DEBUG(_L("CMPXNotInitialisedState::RetrieveFileDetailsL()"));
       
   720 
       
   721     TInt error = KErrNone;
       
   722 
       
   723     if ( iVideoPlaybackCtlr->iPBPluginError != KErrNone )
       
   724     {
       
   725         aMedia->SetTObjectValueL<TInt>(
       
   726             TMPXAttribute( KMPXMediaVideoError ), iVideoPlaybackCtlr->iPBPluginError );
       
   727 
       
   728         iVideoPlaybackCtlr->iPBPluginError = KErrNone;
       
   729     }
       
   730     else
       
   731     {
       
   732         //
       
   733         //  Invalid call for this state
       
   734         //  Send HandleMedia with KErrNotReady
       
   735         //
       
   736         error = KErrNotReady;
       
   737     }
       
   738 
       
   739     return error;
       
   740 }
       
   741 
       
   742 //  ------------------------------------------------------------------------------------------------
       
   743 //  CMPXNotInitialisedState::HandleClose
       
   744 //  ------------------------------------------------------------------------------------------------
       
   745 void CMPXNotInitialisedState::HandleClose()
       
   746 {
       
   747     MPX_DEBUG(_L("CMPXNotInitialisedState::HandleClose()"));
       
   748 
       
   749     iVideoPlaybackCtlr->CloseController();
       
   750 }
       
   751 
       
   752 // -------------------------------------------------------------------------------------------------
       
   753 // CMPXNotInitialisedState::SetAspectRatioL
       
   754 // -------------------------------------------------------------------------------------------------
       
   755 //
       
   756 void CMPXNotInitialisedState::SetAspectRatioL( CMPXCommand& /*aCmd*/, TMMFScalingType /*aType*/ )
       
   757 {
       
   758     MPX_DEBUG(_L("CMPXNotInitialisedState::SetAspectRatioL()"));
       
   759 }
       
   760 
       
   761 // -------------------------------------------------------------------------------------------------
       
   762 //   CMPXNotInitialisedState::HandleUnexpectedError
       
   763 // -------------------------------------------------------------------------------------------------
       
   764 //
       
   765 void CMPXNotInitialisedState::HandleUnexpectedError( TInt /*aError*/ )
       
   766 {
       
   767     MPX_ENTER_EXIT(_L("CMPXNotInitialisedState::HandleUnexpectedError()"));
       
   768 }
       
   769 
       
   770 //  ------------------------------------------------------------------------------------------------
       
   771 //    CMPXNotInitialisedState::HandleBackground()
       
   772 //  ------------------------------------------------------------------------------------------------
       
   773 void CMPXNotInitialisedState::HandleBackground()
       
   774 {
       
   775     MPX_ENTER_EXIT(_L("CMPXNotInitialisedState::HandleBackground()"));
       
   776     CommandHandleBackground();
       
   777 }
       
   778 
       
   779 //  ------------------------------------------------------------------------------------------------
       
   780 //    CMPXNotInitialisedState::HandleForeground()
       
   781 //  ------------------------------------------------------------------------------------------------
       
   782 void CMPXNotInitialisedState::HandleForeground()
       
   783 {
       
   784     MPX_ENTER_EXIT(_L("CMPXNotInitialisedState::HandleForeground()"));
       
   785     CommandHandleForeground();
       
   786 }
       
   787 
       
   788 //  ------------------------------------------------------------------------------------------------
       
   789 //  CMPXNotInitialisedState::HandlePlay()
       
   790 //  ------------------------------------------------------------------------------------------------
       
   791 void CMPXNotInitialisedState::HandlePlay()
       
   792 {
       
   793     MPX_DEBUG(_L("CMPXNotInitialisedState::HandlePlay() Plugin error"));
       
   794 
       
   795      MPX_TRAPD( err, SendErrorToViewL( iVideoPlaybackCtlr->iPBPluginError ) );
       
   796 }
       
   797 
       
   798 // *************************************************************************************************
       
   799 //
       
   800 //                       CMPXInitialisingState
       
   801 //
       
   802 // *************************************************************************************************
       
   803 
       
   804 //  ------------------------------------------------------------------------------------------------
       
   805 //  CMPXInitialisingState::NewL()
       
   806 //  ------------------------------------------------------------------------------------------------
       
   807 CMPXVideoPlaybackState* CMPXInitialisingState::NewL(
       
   808         CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
   809 {
       
   810     MPX_ENTER_EXIT(_L("CMPXInitialisingState::NewL()"));
       
   811 
       
   812     CMPXInitialisingState* self = new( ELeave ) CMPXInitialisingState();
       
   813     CleanupStack::PushL( self );
       
   814     self->ConstructL(aVideoPlaybackCtlr);
       
   815     CleanupStack::Pop();
       
   816     return self;
       
   817 }
       
   818 
       
   819 //  ------------------------------------------------------------------------------------------------
       
   820 //  CMPXInitialisingState::~CMPXInitialisingState()
       
   821 //  ------------------------------------------------------------------------------------------------
       
   822 CMPXInitialisingState::~CMPXInitialisingState()
       
   823 {
       
   824     MPX_DEBUG(_L("CMPXInitialisingState::~CMPXInitialisingState()"));
       
   825 }
       
   826 
       
   827 //  ------------------------------------------------------------------------------------------------
       
   828 //  CMPXInitialisingState::OpenFileL
       
   829 //  ------------------------------------------------------------------------------------------------
       
   830 void CMPXInitialisingState::OpenFileL( const TDesC& aMediaFile )
       
   831 {
       
   832     MPX_ENTER_EXIT(_L("CMPXInitialisingState::OpenFileL()"),
       
   833                    _L("link = %S"), &aMediaFile );
       
   834 
       
   835     iVideoPlaybackCtlr->iPBPluginError = KErrNone;
       
   836 
       
   837     iVideoPlaybackCtlr->iPlaybackMode->OpenFileL( aMediaFile );
       
   838 }
       
   839 
       
   840 //  ----------------------------------------------------------------------------
       
   841 //  CMPXInitialisingState::OpenFileL
       
   842 //  ----------------------------------------------------------------------------
       
   843 void CMPXInitialisingState::OpenFileL( const RFile& aMediaFile )
       
   844 {
       
   845     MPX_ENTER_EXIT(_L("CMPXInitialisingState::OpenFileL()"));
       
   846 
       
   847     // Reset the plugin error
       
   848     iVideoPlaybackCtlr->iPBPluginError = KErrNone;
       
   849 
       
   850     iVideoPlaybackCtlr->iPlaybackMode->OpenFileL( aMediaFile );
       
   851 }
       
   852 
       
   853 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   854 
       
   855 //  ----------------------------------------------------------------------------
       
   856 //  CMPXInitialisingState::OpenFile64L
       
   857 //  ----------------------------------------------------------------------------
       
   858 void CMPXInitialisingState::OpenFile64L( const RFile64& aMediaFile )
       
   859 {
       
   860     MPX_ENTER_EXIT(_L("CMPXInitialisingState::OpenFile64L( RFile64 )"));
       
   861 
       
   862     // Reset the plugin error
       
   863     iVideoPlaybackCtlr->iPBPluginError = KErrNone;
       
   864 
       
   865     iVideoPlaybackCtlr->iPlaybackMode->OpenFile64L( aMediaFile );
       
   866 }
       
   867 
       
   868 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   869 
       
   870 //  ------------------------------------------------------------------------------------------------
       
   871 //    CMPXInitialisingState::RetrieveFileDetailsL
       
   872 //  ------------------------------------------------------------------------------------------------
       
   873 TInt CMPXInitialisingState::RetrieveFileDetailsL( const TArray<TMPXAttribute>& /*aAttrs*/,
       
   874                                                   CMPXMedia* /*aMedia*/ )
       
   875 {
       
   876     MPX_DEBUG(_L("CMPXInitialisingState::RetrieveFileDetailsL()"));
       
   877 
       
   878     //
       
   879     //  Invalid call for this state
       
   880     //  Send HandleMedia with KErrNotReady
       
   881     //
       
   882     return KErrNotReady;
       
   883 }
       
   884 
       
   885 //  ------------------------------------------------------------------------------------------------
       
   886 //    CMPXInitialisingState::HandleOpenComplete()
       
   887 //
       
   888 //    State doesn't change just send prepare to MMF
       
   889 //  ------------------------------------------------------------------------------------------------
       
   890 //
       
   891 void CMPXInitialisingState::HandleOpenComplete( TInt aError )
       
   892 {
       
   893     MPX_ENTER_EXIT(
       
   894         _L("CMPXInitialisingState::HandleOpenComplete()"),
       
   895         _L("error = %d"), aError );
       
   896 
       
   897     if ( aError == KErrNone )
       
   898     {
       
   899         iVideoPlaybackCtlr->iPlaybackMode->HandleOpenComplete();
       
   900 
       
   901         MPX_DEBUG(_L("CMPXInitialisingState::HandleOpenComplete()  Sending Prepare()"));
       
   902 
       
   903         iVideoPlaybackCtlr->iPlayer->Prepare();
       
   904     }
       
   905     else
       
   906     {
       
   907         //
       
   908         // Transistion back to EMPXVideoNotInitialized, for pre loaded plugin
       
   909         // this state will alert the view that pre loading failed
       
   910         //
       
   911         iVideoPlaybackCtlr->ChangeState( EMPXVideoNotInitialized );
       
   912 
       
   913         // Store the error, in case of pre loaded pluging this can
       
   914         // later be sent to the view
       
   915         iVideoPlaybackCtlr->iPBPluginError = aError;
       
   916 
       
   917         //
       
   918         //  move the FW state to Initialized irrespective of the playback state
       
   919         //  This enables the FW to send initailized event to view, which in turn
       
   920         //  queries for the error
       
   921         //
       
   922         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent(
       
   923             MMPXPlaybackPluginObserver::EPInitialised,
       
   924             0,
       
   925             KErrNone );
       
   926     }
       
   927 }
       
   928 
       
   929 //  ------------------------------------------------------------------------------------------------
       
   930 //    CMPXInitialisingState::HandlePrepareComplete
       
   931 //  ------------------------------------------------------------------------------------------------
       
   932 void CMPXInitialisingState::HandlePrepareComplete( TInt aError )
       
   933 {
       
   934     MPX_ENTER_EXIT( _L("CMPXInitialisingState::HandlePrepareComplete()"),
       
   935                     _L("error = %d"), aError);
       
   936 
       
   937     TInt duration = 0;
       
   938 
       
   939     if ( aError == KErrNone || aError == KErrMMPartialPlayback )
       
   940     {
       
   941         // Since PrepareComplete was successful - create post-init state instances needed
       
   942         MPX_TRAPD( error, iVideoPlaybackCtlr->CreatePostInitStatesL() );
       
   943 
       
   944         //
       
   945         //  Read in the file details
       
   946         //
       
   947         MPX_TRAPD( err, iVideoPlaybackCtlr->ReadFileDetailsL() );
       
   948 
       
   949         if ( aError == KErrMMPartialPlayback )
       
   950         {
       
   951             iVideoPlaybackCtlr->iFileDetails->iPartialPlayback = ETrue;
       
   952         }
       
   953 
       
   954         // for streaming playback, we should know whether its LIVE or On-Demand
       
   955         // at this time
       
   956         // in case of live streaming, playback controller's mode would need to change
       
   957         MPX_TRAPD( setModeErr, iVideoPlaybackCtlr->SetPlaybackModeL() );
       
   958 
       
   959         duration = iVideoPlaybackCtlr->iFileDetails->iDuration.Int64() / KPbMilliMultiplier;
       
   960 
       
   961         MPX_TRAPD(setVolErr, iVideoPlaybackCtlr->SetVolumeMMFL());
       
   962 
       
   963         //
       
   964         //  Sent a open request, transistion to EMPXVideoInitialized
       
   965         //
       
   966         iVideoPlaybackCtlr->ChangeState( EMPXVideoInitialized );
       
   967 
       
   968         iVideoPlaybackCtlr->iMPXPluginObs->
       
   969             HandlePluginEvent( MMPXPlaybackPluginObserver::EPInitialised, duration, KErrNone );
       
   970     }
       
   971     else
       
   972     {
       
   973         //
       
   974         // Transistion back to EMPXVideoNotInitialized, for pre loaded plugin
       
   975         // this state will alert the view that pre loading failed
       
   976         //
       
   977         iVideoPlaybackCtlr->ChangeState( EMPXVideoNotInitialized );
       
   978 
       
   979         // Store the error, in case of pre loaded pluging this can
       
   980         // later be sent to the view
       
   981         iVideoPlaybackCtlr->iPBPluginError = aError;
       
   982 
       
   983         //
       
   984         //  move the FW state to Initialized irrespective of the playback state
       
   985         //  This enables the FW to send initailized event to view, which in turn
       
   986         //  queries for the error
       
   987         //
       
   988         iVideoPlaybackCtlr->iMPXPluginObs->
       
   989             HandlePluginEvent( MMPXPlaybackPluginObserver::EPInitialised, 0, KErrNone );
       
   990     }
       
   991 }
       
   992 
       
   993 //  ------------------------------------------------------------------------------------------------
       
   994 //  CMPXInitialisingState::HandleVolumeChange
       
   995 //  ------------------------------------------------------------------------------------------------
       
   996 void CMPXInitialisingState::HandleVolumeChange()
       
   997 {
       
   998     MPX_DEBUG(_L("CMPXInitialisingState::HandleVolumeChange()"));
       
   999 }
       
  1000 
       
  1001 // -------------------------------------------------------------------------------------------------
       
  1002 // CMPXInitialisingState::SetAspectRatioL
       
  1003 // -------------------------------------------------------------------------------------------------
       
  1004 //
       
  1005 void CMPXInitialisingState::SetAspectRatioL( CMPXCommand& /*aCmd*/, TMMFScalingType /*aType*/ )
       
  1006 {
       
  1007     MPX_DEBUG(_L("CMPXInitialisingState::SetAspectRatioL()"));
       
  1008 }
       
  1009 
       
  1010 // -------------------------------------------------------------------------------------------------
       
  1011 //   CMPXInitialisingState::HandleUnexpectedError
       
  1012 // -------------------------------------------------------------------------------------------------
       
  1013 //
       
  1014 void CMPXInitialisingState::HandleUnexpectedError( TInt /*aError*/ )
       
  1015 {
       
  1016     MPX_ENTER_EXIT(_L("CMPXInitialisingState::HandleUnexpectedError()"));
       
  1017 }
       
  1018 
       
  1019 //  ------------------------------------------------------------------------------------------------
       
  1020 //    CMPXInitialisingState::HandleBackground()
       
  1021 //  ------------------------------------------------------------------------------------------------
       
  1022 void CMPXInitialisingState::HandleBackground()
       
  1023 {
       
  1024     MPX_ENTER_EXIT(_L("CMPXInitialisingState::HandleBackground()"));
       
  1025     CommandHandleBackground();
       
  1026 }
       
  1027 
       
  1028 //  ------------------------------------------------------------------------------------------------
       
  1029 //    CMPXInitialisingState::HandleForeground()
       
  1030 //  ------------------------------------------------------------------------------------------------
       
  1031 void CMPXInitialisingState::HandleForeground()
       
  1032 {
       
  1033     MPX_ENTER_EXIT(_L("CMPXInitialisingState::HandleForeground()"));
       
  1034     CommandHandleForeground();
       
  1035 }
       
  1036 
       
  1037 // *************************************************************************************************
       
  1038 //
       
  1039 //                       CMPXInitialisedState
       
  1040 //
       
  1041 // *************************************************************************************************
       
  1042 
       
  1043 //  ------------------------------------------------------------------------------------------------
       
  1044 //  CMPXInitialisedState::NewL()
       
  1045 //  ------------------------------------------------------------------------------------------------
       
  1046 CMPXVideoPlaybackState* CMPXInitialisedState::NewL(
       
  1047         CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
  1048 {
       
  1049     MPX_ENTER_EXIT(_L("CMPXInitialisedState::NewL()"));
       
  1050 
       
  1051     CMPXInitialisedState* self = new( ELeave ) CMPXInitialisedState();
       
  1052     CleanupStack::PushL( self );
       
  1053     self->ConstructL(aVideoPlaybackCtlr);
       
  1054     CleanupStack::Pop();
       
  1055     return self;
       
  1056 }
       
  1057 
       
  1058 //  ------------------------------------------------------------------------------------------------
       
  1059 //  CMPXInitialisedState::~CMPXInitialisedState()
       
  1060 //  ------------------------------------------------------------------------------------------------
       
  1061 CMPXInitialisedState::~CMPXInitialisedState()
       
  1062 {
       
  1063     MPX_DEBUG(_L("CMPXInitialisedState::~CMPXInitialisedState()"));
       
  1064 }
       
  1065 
       
  1066 //  ------------------------------------------------------------------------------------------------
       
  1067 //  CMPXInitialisedState::HandlePlay()
       
  1068 //  ------------------------------------------------------------------------------------------------
       
  1069 void CMPXInitialisedState::HandlePlay()
       
  1070 {
       
  1071     MPX_DEBUG(_L("CMPXInitialisedState::HandlePlay()"));
       
  1072 
       
  1073     if ( iVideoPlaybackCtlr->iPlaybackMode->CanPlayNow() )
       
  1074     {
       
  1075         iVideoPlaybackCtlr->iForegroundPause = EFalse;
       
  1076 
       
  1077         iVideoPlaybackCtlr->iPlayer->Play();
       
  1078 
       
  1079         iVideoPlaybackCtlr->ChangeState( EMPXVideoBuffering );
       
  1080 
       
  1081         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPBufferingStarted,
       
  1082                                                               0,
       
  1083                                                               KErrNone );
       
  1084     }
       
  1085     else
       
  1086     {
       
  1087         iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
       
  1088     }
       
  1089 
       
  1090     iVideoPlaybackCtlr->iAllowAutoPlay = ETrue;
       
  1091 }
       
  1092 
       
  1093 //  ------------------------------------------------------------------------------------------------
       
  1094 //  CMPXInitialisedState::HandleSetPositionL()
       
  1095 //  ------------------------------------------------------------------------------------------------
       
  1096 void CMPXInitialisedState::HandleSetPositionL( TInt aPosition )
       
  1097 {
       
  1098     MPX_ENTER_EXIT(_L("CMPXInitialisedState::HandleSetPositionL()"),
       
  1099                    _L("position = %d"), aPosition );
       
  1100 
       
  1101     if ( iVideoPlaybackCtlr->iFileDetails->iSeekable )
       
  1102     {
       
  1103         TInt64 pos( aPosition );
       
  1104 
       
  1105         pos *= KPbMilliMultiplier;
       
  1106 
       
  1107         //
       
  1108         //  No need to set position unless it is not 0
       
  1109         //
       
  1110         if ( pos != 0 )
       
  1111         {
       
  1112         	iVideoPlaybackCtlr->iPlayer->SetPositionL( pos );
       
  1113         }
       
  1114     }
       
  1115     else
       
  1116     {
       
  1117         MPX_DEBUG(_L("CMPXInitialisedState::HandleSetPosition() FAIL - file is not seekable"));
       
  1118     }
       
  1119 }
       
  1120 
       
  1121 //  ------------------------------------------------------------------------------------------------
       
  1122 //    CMPXInitialisedState::HandleStop()
       
  1123 //  ------------------------------------------------------------------------------------------------
       
  1124 void CMPXInitialisedState::HandleStop()
       
  1125 {
       
  1126     MPX_ENTER_EXIT(_L("CMPXInitialisedState::HandleStop()"));
       
  1127 
       
  1128     iVideoPlaybackCtlr->iPlayer->Stop();
       
  1129 
       
  1130     iVideoPlaybackCtlr->ChangeState( EMPXVideoStopped );
       
  1131 
       
  1132     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPStopped,
       
  1133                                                           0,
       
  1134                                                           KErrNone );
       
  1135 }
       
  1136 
       
  1137 //  ------------------------------------------------------------------------------------------------
       
  1138 //    CMPXInitialisedState::HandleBackground()
       
  1139 //  ------------------------------------------------------------------------------------------------
       
  1140 void CMPXInitialisedState::HandleBackground()
       
  1141 {
       
  1142     MPX_ENTER_EXIT(_L("CMPXInitialisedState::HandleBackground()"));
       
  1143     CommandHandleBackground();
       
  1144 }
       
  1145 
       
  1146 //  ------------------------------------------------------------------------------------------------
       
  1147 //    CMPXInitialisedState::HandleForeground()
       
  1148 //  ------------------------------------------------------------------------------------------------
       
  1149 void CMPXInitialisedState::HandleForeground()
       
  1150 {
       
  1151     MPX_ENTER_EXIT(_L("CMPXInitialisedState::HandleForeground()"));
       
  1152     CommandHandleForeground();
       
  1153 }
       
  1154 
       
  1155 // *************************************************************************************************
       
  1156 //
       
  1157 //                          CMPXPlayingState
       
  1158 //
       
  1159 // *************************************************************************************************
       
  1160 
       
  1161 //  ------------------------------------------------------------------------------------------------
       
  1162 //  CMPXPlayingState::NewL()
       
  1163 //  ------------------------------------------------------------------------------------------------
       
  1164 CMPXVideoPlaybackState* CMPXPlayingState::NewL(
       
  1165         CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
  1166 {
       
  1167     MPX_ENTER_EXIT(_L("CMPXPlayingState::NewL()"));
       
  1168 
       
  1169     CMPXPlayingState* self = new( ELeave ) CMPXPlayingState();
       
  1170     CleanupStack::PushL( self );
       
  1171     self->ConstructL(aVideoPlaybackCtlr);
       
  1172     CleanupStack::Pop();
       
  1173     return self;
       
  1174 }
       
  1175 
       
  1176 //  ------------------------------------------------------------------------------------------------
       
  1177 //  CMPXPlayingState::~CMPXPlayingState()
       
  1178 //  ------------------------------------------------------------------------------------------------
       
  1179 CMPXPlayingState::~CMPXPlayingState()
       
  1180 {
       
  1181     MPX_DEBUG(_L("CMPXPlayingState::~CMPXPlayingState()"));
       
  1182 }
       
  1183 
       
  1184 //  ------------------------------------------------------------------------------------------------
       
  1185 //  CMPXPlayingState::HandleLoadingStarted()
       
  1186 //  ------------------------------------------------------------------------------------------------
       
  1187 void CMPXPlayingState::HandleLoadingStarted()
       
  1188 {
       
  1189     MPX_DEBUG(_L("CMPXPlayingState::HandleLoadingStarted()"));
       
  1190 
       
  1191     TInt loadingPercentage(0);
       
  1192 
       
  1193     MPX_TRAPD( error, iVideoPlaybackCtlr->iPlayer->GetVideoLoadingProgressL( loadingPercentage ) );
       
  1194 
       
  1195     if ( error == KErrNone )
       
  1196     {
       
  1197         MPX_DEBUG(_L("CMPXPlayingState::HandleLoadingStarted() Loading = %d"), loadingPercentage);
       
  1198 
       
  1199         // if buffering is 100% - there is no need to transition to Buffering state
       
  1200         if ( loadingPercentage < 100 )
       
  1201         {
       
  1202             iVideoPlaybackCtlr->ChangeState( EMPXVideoBuffering );
       
  1203             iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent(
       
  1204                                                    MMPXPlaybackPluginObserver::EPBufferingStarted,
       
  1205                                                    0,
       
  1206                                                    KErrNone );
       
  1207         }
       
  1208     }
       
  1209     else
       
  1210     {
       
  1211         MPX_TRAPD( err, SendErrorToViewL( error ) );
       
  1212     }
       
  1213 }
       
  1214 
       
  1215 //  ------------------------------------------------------------------------------------------------
       
  1216 //  CMPXPlayingState::HandleStop()
       
  1217 //  ------------------------------------------------------------------------------------------------
       
  1218 void CMPXPlayingState::HandleStop()
       
  1219 {
       
  1220     MPX_ENTER_EXIT(_L("CMPXPlayingState::HandleStop()"));
       
  1221 
       
  1222     iVideoPlaybackCtlr->iPlayer->Stop();
       
  1223 
       
  1224     iVideoPlaybackCtlr->ChangeState(EMPXVideoStopped);
       
  1225 
       
  1226     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPStopped,
       
  1227                                                           0,
       
  1228                                                           KErrNone );
       
  1229 }
       
  1230 
       
  1231 //  ------------------------------------------------------------------------------------------------
       
  1232 //  CMPXPlayingState::HandlePause()
       
  1233 //  ------------------------------------------------------------------------------------------------
       
  1234 void CMPXPlayingState::HandlePause()
       
  1235 {
       
  1236     MPX_ENTER_EXIT(_L("CMPXPlayingState::HandlePause()"));
       
  1237 
       
  1238     iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
       
  1239 }
       
  1240 
       
  1241 //  ------------------------------------------------------------------------------------------------
       
  1242 //    CMPXPlayingState::HandlePlayPause()
       
  1243 //
       
  1244 //  ------------------------------------------------------------------------------------------------
       
  1245 void CMPXPlayingState::HandlePlayPause()
       
  1246 {
       
  1247     MPX_DEBUG(_L("CMPXPlayingState::HandlePlayPause()"));
       
  1248     HandlePause();
       
  1249 }
       
  1250 
       
  1251 //  ------------------------------------------------------------------------------------------------
       
  1252 //  CMPXPlayingState::HandleStartSeekL()
       
  1253 //  ------------------------------------------------------------------------------------------------
       
  1254 void CMPXPlayingState::HandleStartSeekL( TBool aForward )
       
  1255 {
       
  1256     MPX_ENTER_EXIT(_L("CMPXPlayingState::HandleStartSeekL()"));
       
  1257 
       
  1258     if ( iVideoPlaybackCtlr->iFileDetails->iSeekable )
       
  1259     {
       
  1260         TTimeIntervalMicroSeconds pos = iVideoPlaybackCtlr->iPlayer->PositionL();
       
  1261 
       
  1262         iVideoPlaybackCtlr->iVideoSeeker->StartSeekingL(
       
  1263             aForward,
       
  1264             GetState(),
       
  1265             pos.Int64(),
       
  1266             iVideoPlaybackCtlr->iFileDetails->iDuration.Int64() );
       
  1267 
       
  1268         iVideoPlaybackCtlr->ChangeState( EMPXVideoSeeking );
       
  1269 
       
  1270         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent(
       
  1271             MMPXPlaybackPluginObserver::EPPluginSeeking,
       
  1272             0,
       
  1273             KErrNone );
       
  1274     }
       
  1275     else
       
  1276     {
       
  1277         MPX_DEBUG(_L("CMPXPlayingState::HandleStartSeek() FAIL - file is not seekable"));
       
  1278     }
       
  1279 }
       
  1280 
       
  1281 //  ------------------------------------------------------------------------------------------------
       
  1282 //  CMPXPlayingState::HandleSetPositionL()
       
  1283 //  ------------------------------------------------------------------------------------------------
       
  1284 void CMPXPlayingState::HandleSetPositionL( TInt aPosition )
       
  1285 {
       
  1286     MPX_ENTER_EXIT(_L("CMPXPlayingState::HandleSetPositionL()"),
       
  1287                    _L("position = %d"), aPosition );
       
  1288 
       
  1289     if ( iVideoPlaybackCtlr->iFileDetails->iSeekable )
       
  1290     {
       
  1291         TInt64 pos( aPosition );
       
  1292 
       
  1293         pos *= KPbMilliMultiplier;
       
  1294 
       
  1295         //
       
  1296         // Helix can't handle setposition in playing state
       
  1297         //
       
  1298         iVideoPlaybackCtlr->iPlayer->PauseL();
       
  1299         iVideoPlaybackCtlr->iPlayer->SetPositionL( pos );
       
  1300         iVideoPlaybackCtlr->iPlayer->Play();
       
  1301     }
       
  1302     else
       
  1303     {
       
  1304         MPX_DEBUG(_L("CMPXPlayingState::HandleSetPosition() FAIL - file is not seekable"));
       
  1305     }
       
  1306 }
       
  1307 
       
  1308 //  ------------------------------------------------------------------------------------------------
       
  1309 //  CMPXPlayingState::ResolveTimeoutError()
       
  1310 //  ------------------------------------------------------------------------------------------------
       
  1311 void CMPXPlayingState::ResolveTimeoutError( TInt aError )
       
  1312 {
       
  1313     MPX_ENTER_EXIT(_L("CMPXPlayingState::ResolveTimeoutError()"),
       
  1314                    _L("aError = %d"), aError );
       
  1315 
       
  1316     // Timeout while playing. Show disconnect dialog.
       
  1317     MPX_TRAPD( err, SendErrorToViewL( KErrDisconnected ) );
       
  1318 }
       
  1319 
       
  1320 //  ------------------------------------------------------------------------------------------------
       
  1321 //    CMPXPlayingState::HandleBackground()
       
  1322 //  ------------------------------------------------------------------------------------------------
       
  1323 void CMPXPlayingState::HandleBackground()
       
  1324 {
       
  1325     MPX_ENTER_EXIT(_L("CMPXPlayingState::HandleBackground()"));
       
  1326     iVideoPlaybackCtlr->iPlaybackMode->HandleBackground();
       
  1327 }
       
  1328 
       
  1329 //  ------------------------------------------------------------------------------------------------
       
  1330 //  CMPXPlayingState::HandleCustomPause()
       
  1331 //  As the custom pause can only be sent for non-live playback
       
  1332 //  There is no need to call the  playback mode class to handle the custom pause
       
  1333 //  ------------------------------------------------------------------------------------------------
       
  1334 void CMPXPlayingState::HandleCustomPause()
       
  1335 {
       
  1336     MPX_ENTER_EXIT(_L("CMPXPlayingState::HandleCustomPause()"));
       
  1337 
       
  1338     MPX_TRAPD( err, iVideoPlaybackCtlr->iPlayer->PauseL() );
       
  1339 
       
  1340     if ( err == KErrNone )
       
  1341     {
       
  1342         iVideoPlaybackCtlr->ChangeState( EMPXVideoPaused );
       
  1343     }
       
  1344     else
       
  1345     {
       
  1346         TRAP_IGNORE( iVideoPlaybackCtlr->iState->SendErrorToViewL( err ) );
       
  1347     }
       
  1348 }
       
  1349 
       
  1350 // *************************************************************************************************
       
  1351 //
       
  1352 //                          CMPXPausedState
       
  1353 //
       
  1354 // *************************************************************************************************
       
  1355 
       
  1356 //  ------------------------------------------------------------------------------------------------
       
  1357 //  CMPXVideoPlaybackState* CMPXPausedState::NewL()
       
  1358 //  ------------------------------------------------------------------------------------------------
       
  1359 CMPXVideoPlaybackState* CMPXPausedState::NewL( CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
  1360 {
       
  1361     MPX_ENTER_EXIT(_L("CMPXPausedState::NewL()"));
       
  1362 
       
  1363     CMPXPausedState* self = new( ELeave ) CMPXPausedState();
       
  1364     CleanupStack::PushL( self );
       
  1365     self->ConstructL(aVideoPlaybackCtlr);
       
  1366     CleanupStack::Pop();
       
  1367     return self;
       
  1368 }
       
  1369 
       
  1370 //  ------------------------------------------------------------------------------------------------
       
  1371 //  CMPXPausedState::~CMPXPausedState()
       
  1372 //  ------------------------------------------------------------------------------------------------
       
  1373 CMPXPausedState::~CMPXPausedState()
       
  1374 {
       
  1375     MPX_DEBUG(_L("CMPXPausedState::~CMPXPausedState()"));
       
  1376 }
       
  1377 
       
  1378 //  ------------------------------------------------------------------------------------------------
       
  1379 //  CMPXPausedState::HandlePlay()
       
  1380 //  ------------------------------------------------------------------------------------------------
       
  1381 void CMPXPausedState::HandlePlay()
       
  1382 {
       
  1383     MPX_ENTER_EXIT(_L("CMPXPausedState::HandlePlay()"));
       
  1384 
       
  1385     if ( iVideoPlaybackCtlr->iPlaybackMode->CanPlayNow() )
       
  1386     {
       
  1387         iVideoPlaybackCtlr->iForegroundPause = EFalse;
       
  1388 
       
  1389         iVideoPlaybackCtlr->iPlayer->Play();
       
  1390 
       
  1391         iVideoPlaybackCtlr->ChangeState(EMPXVideoPlaying);
       
  1392 
       
  1393         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlaying,
       
  1394                                                               0,
       
  1395                                                               KErrNone );
       
  1396     }
       
  1397 }
       
  1398 
       
  1399 //  ------------------------------------------------------------------------------------------------
       
  1400 //    CMPXPausedState::HandlePlayPause()
       
  1401 //  ------------------------------------------------------------------------------------------------
       
  1402 void CMPXPausedState::HandlePlayPause()
       
  1403 {
       
  1404     MPX_DEBUG(_L("CMPXPausedState::HandlePlayPause()"));
       
  1405     HandlePlay();
       
  1406 }
       
  1407 
       
  1408 //  ------------------------------------------------------------------------------------------------
       
  1409 //  CMPXPausedState::HandleSetPositionL()
       
  1410 //  ------------------------------------------------------------------------------------------------
       
  1411 void CMPXPausedState::HandleSetPositionL( TInt aPosition )
       
  1412 {
       
  1413     MPX_ENTER_EXIT(_L("CMPXPausedState::HandleSetPositionL()"),
       
  1414                    _L("position = %d"), aPosition );
       
  1415 
       
  1416     if ( iVideoPlaybackCtlr->iFileDetails->iSeekable )
       
  1417     {
       
  1418         TInt64 pos( aPosition );
       
  1419 
       
  1420         pos *= KPbMilliMultiplier;
       
  1421 
       
  1422         iVideoPlaybackCtlr->iPlayer->SetPositionL( pos );
       
  1423     }
       
  1424     else
       
  1425     {
       
  1426         MPX_DEBUG(_L("CMPXPausedState::HandleSetPosition() FAIL - file is not seekable"));
       
  1427     }
       
  1428 }
       
  1429 
       
  1430 //  ------------------------------------------------------------------------------------------------
       
  1431 //  CMPXPausedState::HandleStop()
       
  1432 //  ------------------------------------------------------------------------------------------------
       
  1433 void CMPXPausedState::HandleStop()
       
  1434 {
       
  1435     MPX_ENTER_EXIT(_L("CMPXPausedState::HandleStop()"));
       
  1436 
       
  1437     iVideoPlaybackCtlr->iPlayer->Stop();
       
  1438 
       
  1439     iVideoPlaybackCtlr->ChangeState(EMPXVideoStopped);
       
  1440 
       
  1441     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPStopped,
       
  1442                                                           0,
       
  1443                                                           KErrNone );
       
  1444 }
       
  1445 
       
  1446 //  ------------------------------------------------------------------------------------------------
       
  1447 //  CMPXPausedState::HandleStartSeekL()
       
  1448 //  ------------------------------------------------------------------------------------------------
       
  1449 void CMPXPausedState::HandleStartSeekL( TBool aForward )
       
  1450 {
       
  1451     MPX_ENTER_EXIT(_L("CMPXPausedState::HandleStartSeekL()"));
       
  1452 
       
  1453     if ( iVideoPlaybackCtlr->iFileDetails->iSeekable )
       
  1454     {
       
  1455         TTimeIntervalMicroSeconds pos = iVideoPlaybackCtlr->iPlayer->PositionL();
       
  1456 
       
  1457         iVideoPlaybackCtlr->iVideoSeeker->StartSeekingL(
       
  1458             aForward,
       
  1459             GetState(),
       
  1460             pos.Int64(),
       
  1461             iVideoPlaybackCtlr->iFileDetails->iDuration.Int64() );
       
  1462 
       
  1463         iVideoPlaybackCtlr->ChangeState( EMPXVideoSeeking );
       
  1464 
       
  1465         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent(
       
  1466             MMPXPlaybackPluginObserver::EPPluginSeeking,
       
  1467             0,
       
  1468             KErrNone );
       
  1469     }
       
  1470     else
       
  1471     {
       
  1472         MPX_DEBUG(_L("CMPXPlayingState::HandleStartSeek() FAIL - file is not seekable"));
       
  1473     }
       
  1474 }
       
  1475 
       
  1476 //  ------------------------------------------------------------------------------------------------
       
  1477 //    CMPXPausedState::HandleForeground()
       
  1478 //  ------------------------------------------------------------------------------------------------
       
  1479 void CMPXPausedState::HandleForeground()
       
  1480 {
       
  1481     MPX_ENTER_EXIT(_L("CMPXPausedState::HandleForeground()"),
       
  1482                    _L("foreground pause = %d"), iVideoPlaybackCtlr->iForegroundPause );
       
  1483 
       
  1484     if ( iVideoPlaybackCtlr->iForegroundPause )
       
  1485     {
       
  1486         iVideoPlaybackCtlr->iState->HandlePlay();
       
  1487     }
       
  1488 }
       
  1489 
       
  1490 //  ------------------------------------------------------------------------------------------------
       
  1491 //  CMPXPausedState::HandleCustomPlay()
       
  1492 //  Handle the custom play command only when in paused state
       
  1493 //  ------------------------------------------------------------------------------------------------
       
  1494 void CMPXPausedState::HandleCustomPlay()
       
  1495 {
       
  1496     MPX_ENTER_EXIT(_L("CMPXPausedState::HandleCustomPlay()"));
       
  1497 
       
  1498     if ( iVideoPlaybackCtlr->iPlaybackMode->CanPlayNow() )
       
  1499     {
       
  1500         iVideoPlaybackCtlr->iForegroundPause = EFalse;
       
  1501 
       
  1502         iVideoPlaybackCtlr->iPlayer->Play();
       
  1503 
       
  1504         iVideoPlaybackCtlr->ChangeState(EMPXVideoPlaying);
       
  1505     }
       
  1506 }
       
  1507 
       
  1508 // *************************************************************************************************
       
  1509 //
       
  1510 //                          CMPXStoppedState
       
  1511 //
       
  1512 // *************************************************************************************************
       
  1513 
       
  1514 //  ------------------------------------------------------------------------------------------------
       
  1515 //  CMPXStoppedState::NewL()
       
  1516 //  ------------------------------------------------------------------------------------------------
       
  1517 CMPXVideoPlaybackState* CMPXStoppedState::NewL( CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
  1518 {
       
  1519     MPX_ENTER_EXIT(_L("CMPXStoppedState::NewL()"));
       
  1520 
       
  1521     CMPXStoppedState* self = new( ELeave ) CMPXStoppedState();
       
  1522     CleanupStack::PushL( self );
       
  1523     self->ConstructL(aVideoPlaybackCtlr);
       
  1524     CleanupStack::Pop();
       
  1525     return self;
       
  1526 }
       
  1527 //  ------------------------------------------------------------------------------------------------
       
  1528 //  CMPXStoppedState::~CMPXStoppedState()
       
  1529 //  ------------------------------------------------------------------------------------------------
       
  1530 CMPXStoppedState::~CMPXStoppedState()
       
  1531 {
       
  1532     MPX_DEBUG(_L("CMPXStoppedState::~CMPXStoppedState()"));
       
  1533 }
       
  1534 
       
  1535 //  ------------------------------------------------------------------------------------------------
       
  1536 //  CMPXStoppedState::HandlePlay()
       
  1537 //  ------------------------------------------------------------------------------------------------
       
  1538 void CMPXStoppedState::HandlePlay()
       
  1539 {
       
  1540     MPX_DEBUG(_L("CMPXStoppedState::HandlePlay()"));
       
  1541 
       
  1542     if ( iVideoPlaybackCtlr->iPlaybackMode->CanPlayNow() )
       
  1543     {
       
  1544         iVideoPlaybackCtlr->iPlayer->Play();
       
  1545 
       
  1546         iVideoPlaybackCtlr->ChangeState(EMPXVideoPlaying);
       
  1547 
       
  1548         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlaying,
       
  1549                                                               0,
       
  1550                                                               KErrNone );
       
  1551     }
       
  1552 }
       
  1553 
       
  1554 //  ------------------------------------------------------------------------------------------------
       
  1555 //  CMPXStoppedState::HandleSetPositionL()
       
  1556 //  ------------------------------------------------------------------------------------------------
       
  1557 void CMPXStoppedState::HandleSetPositionL(TInt aPosition)
       
  1558 {
       
  1559     MPX_ENTER_EXIT(_L("CMPXStoppedState::HandleSetPositionL()"),
       
  1560                    _L("position = %d"), aPosition );
       
  1561 
       
  1562     if ( iVideoPlaybackCtlr->iFileDetails->iSeekable )
       
  1563     {
       
  1564         TInt64 pos( aPosition );
       
  1565 
       
  1566         pos *= KPbMilliMultiplier;
       
  1567 
       
  1568         iVideoPlaybackCtlr->iPlayer->SetPositionL( pos );
       
  1569     }
       
  1570     else
       
  1571     {
       
  1572         MPX_DEBUG(_L("CMPXStoppedState::HandleSetPosition() FAIL - file is not seekable"));
       
  1573     }
       
  1574 }
       
  1575 
       
  1576 //  ------------------------------------------------------------------------------------------------
       
  1577 //  CMPXStoppedState::HandleClose
       
  1578 //  ------------------------------------------------------------------------------------------------
       
  1579 void CMPXStoppedState::HandleClose()
       
  1580 {
       
  1581     MPX_ENTER_EXIT(_L("CMPXStoppedState::HandleClose()"));
       
  1582 
       
  1583     iVideoPlaybackCtlr->CloseController();
       
  1584 
       
  1585     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPClosed,
       
  1586                                                           0,
       
  1587                                                           KErrNone );
       
  1588 }
       
  1589 
       
  1590 //  ------------------------------------------------------------------------------------------------
       
  1591 //  CMPXStoppedState::ResolveTimeoutError()
       
  1592 //  ------------------------------------------------------------------------------------------------
       
  1593 void CMPXStoppedState::ResolveTimeoutError( TInt aError )
       
  1594 {
       
  1595     MPX_ENTER_EXIT(_L("CMPXStoppedState::ResolveTimeoutError()"),
       
  1596                    _L("aError = %d"), aError );
       
  1597 
       
  1598     // Don't handle the error. Already in the stopped state
       
  1599 }
       
  1600 
       
  1601 // *************************************************************************************************
       
  1602 //
       
  1603 //                          CMPXBufferingState
       
  1604 //
       
  1605 // *************************************************************************************************
       
  1606 
       
  1607 //  ------------------------------------------------------------------------------------------------
       
  1608 //  CMPXBufferingState::NewL()
       
  1609 //  ------------------------------------------------------------------------------------------------
       
  1610 CMPXVideoPlaybackState* CMPXBufferingState::NewL( CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
  1611 {
       
  1612     MPX_ENTER_EXIT(_L("CMPXBufferingState::NewL()"));
       
  1613 
       
  1614     CMPXBufferingState* self = new( ELeave ) CMPXBufferingState();
       
  1615     CleanupStack::PushL( self );
       
  1616     self->ConstructL(aVideoPlaybackCtlr);
       
  1617     CleanupStack::Pop();
       
  1618     return self;
       
  1619 }
       
  1620 
       
  1621 //  ------------------------------------------------------------------------------------------------
       
  1622 //  CMPXBufferingState::~CMPXBufferingState()
       
  1623 //  ------------------------------------------------------------------------------------------------
       
  1624 CMPXBufferingState::~CMPXBufferingState()
       
  1625 {
       
  1626     MPX_DEBUG(_L("CMPXBufferingState::~CMPXBufferingState()"));
       
  1627 }
       
  1628 
       
  1629 //  ------------------------------------------------------------------------------------------------
       
  1630 //  CMPXBufferingState::HandleLoadingStarted()
       
  1631 //
       
  1632 //  We transition to Buffering state after Play command is issued initially
       
  1633 //
       
  1634 //  No state transitions necessary here as we are already in Buffering state
       
  1635 //  ------------------------------------------------------------------------------------------------
       
  1636 void CMPXBufferingState::HandleLoadingStarted()
       
  1637 {
       
  1638     MPX_DEBUG(_L("CMPXBufferingState::HandleLoadingStarted()"));
       
  1639 
       
  1640     // no need to send any events - we are already in buffering state
       
  1641 }
       
  1642 
       
  1643 //  ------------------------------------------------------------------------------------------------
       
  1644 //  CMPXBufferingState::HandleLoadingComplete()
       
  1645 //  ------------------------------------------------------------------------------------------------
       
  1646 void CMPXBufferingState::HandleLoadingComplete( TInt aError )
       
  1647 {
       
  1648     MPX_ENTER_EXIT(_L("CMPXBufferingState::HandleLoadingComplete()"),
       
  1649                    _L("error = %d"), aError );
       
  1650 
       
  1651     if ( aError == KErrNone )
       
  1652     {
       
  1653         if ( iVideoPlaybackCtlr->iAppInForeground && !iVideoPlaybackCtlr->iForegroundPause )
       
  1654         {
       
  1655             iVideoPlaybackCtlr->ChangeState( EMPXVideoPlaying );
       
  1656 
       
  1657             iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent(
       
  1658                                                     MMPXPlaybackPluginObserver::EPPlaying,
       
  1659                                                     0,
       
  1660                                                     KErrNone );
       
  1661         }
       
  1662         else
       
  1663         {
       
  1664             //  delayed pause :
       
  1665             //  background event was received while we were in buffering state
       
  1666             iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
       
  1667         }
       
  1668     }
       
  1669     else
       
  1670     {
       
  1671         HandleClose();
       
  1672     }
       
  1673 }
       
  1674 
       
  1675 //  ------------------------------------------------------------------------------------------------
       
  1676 //    CMPXBufferingState::HandleStop()
       
  1677 //  ------------------------------------------------------------------------------------------------
       
  1678 void CMPXBufferingState::HandleStop()
       
  1679 {
       
  1680     MPX_ENTER_EXIT(_L("CMPXBufferingState::HandleStop()"));
       
  1681 
       
  1682     iVideoPlaybackCtlr->iPlayer->Stop();
       
  1683 
       
  1684     iVideoPlaybackCtlr->ChangeState( EMPXVideoStopped );
       
  1685 
       
  1686     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPStopped,
       
  1687                                                           0,
       
  1688                                                           KErrNone );
       
  1689 }
       
  1690 
       
  1691 //  ------------------------------------------------------------------------------------------------
       
  1692 //  CMPXBufferingState::HandleBackground()
       
  1693 //  ------------------------------------------------------------------------------------------------
       
  1694 void CMPXBufferingState::HandleBackground()
       
  1695 {
       
  1696     MPX_DEBUG(_L("CMPXBufferingState::HandleBackground()"));
       
  1697 
       
  1698     // we are in buffering state and received a background event
       
  1699     // we cannot pause now but need to pause when buffering is complete
       
  1700     iVideoPlaybackCtlr->iPlaybackMode->HandleBackground();
       
  1701 }
       
  1702 
       
  1703 //  ------------------------------------------------------------------------------------------------
       
  1704 //  CMPXBufferingState::HandleForeground()
       
  1705 //  ------------------------------------------------------------------------------------------------
       
  1706 void CMPXBufferingState::HandleForeground()
       
  1707 {
       
  1708     MPX_DEBUG(_L("CMPXBufferingState::HandleForeground()"));
       
  1709 
       
  1710     // we are in buffering state and received a background event
       
  1711     // we cannot pause now but need to pause when buffering is complete
       
  1712 }
       
  1713 
       
  1714 //  ------------------------------------------------------------------------------------------------
       
  1715 //    CMPXBufferingState::HandlePause()
       
  1716 //  ------------------------------------------------------------------------------------------------
       
  1717 void CMPXBufferingState::HandlePause()
       
  1718 {
       
  1719     MPX_DEBUG(_L("CMPXBufferingState::HandlePause()"));
       
  1720 
       
  1721     //
       
  1722     //  PDL must take action on the pause while buffering when the download is paused
       
  1723     //
       
  1724     if ( iVideoPlaybackCtlr->iPlaybackMode->IsDownloadPaused() )
       
  1725     {
       
  1726         iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
       
  1727     }
       
  1728 }
       
  1729 
       
  1730 //  ------------------------------------------------------------------------------------------------
       
  1731 //  CMPXBufferingState::ResolveTimeoutError()
       
  1732 //  ------------------------------------------------------------------------------------------------
       
  1733 void CMPXBufferingState::ResolveTimeoutError( TInt aError )
       
  1734 {
       
  1735     MPX_ENTER_EXIT(_L("CMPXBufferingState::ResolveTimeoutError()"),
       
  1736                    _L("aError = %d"), aError );
       
  1737 
       
  1738     // Timeout while buffering. Show buffer error.
       
  1739     MPX_TRAPD( err, SendErrorToViewL( KErrTimedOut ) );
       
  1740 }
       
  1741 
       
  1742 //  ------------------------------------------------------------------------------------------------
       
  1743 //    CMPXBufferingState::RetrieveBufferingPercentage()
       
  1744 //  ------------------------------------------------------------------------------------------------
       
  1745 TInt CMPXBufferingState::RetrieveBufferingPercentage()
       
  1746 {
       
  1747     TInt loadingProgress( 0 );
       
  1748 
       
  1749     MPX_TRAPD( error, iVideoPlaybackCtlr->iPlayer->GetVideoLoadingProgressL( loadingProgress ) );
       
  1750     MPX_DEBUG(_L("CMPXBufferingState::RetrieveBufferingPercentage(%d)"), loadingProgress);
       
  1751 
       
  1752     return loadingProgress;
       
  1753 }
       
  1754 
       
  1755 // *************************************************************************************************
       
  1756 //
       
  1757 //                          CMPXSeekingState
       
  1758 //
       
  1759 // *************************************************************************************************
       
  1760 
       
  1761 //  ------------------------------------------------------------------------------------------------
       
  1762 //  CMPXSeekingState::NewL()
       
  1763 //  ------------------------------------------------------------------------------------------------
       
  1764 CMPXVideoPlaybackState* CMPXSeekingState::NewL( CMPXVideoPlaybackController* aVideoPlaybackCtlr )
       
  1765 {
       
  1766     MPX_ENTER_EXIT(_L("CMPXSeekingState::NewL()"));
       
  1767 
       
  1768     CMPXSeekingState* self = new( ELeave ) CMPXSeekingState();
       
  1769     CleanupStack::PushL( self );
       
  1770     self->ConstructL(aVideoPlaybackCtlr);
       
  1771     CleanupStack::Pop();
       
  1772     return self;
       
  1773 }
       
  1774 
       
  1775 //  ------------------------------------------------------------------------------------------------
       
  1776 //  CMPXSeekingState::~CMPXSeekingState()
       
  1777 //  ------------------------------------------------------------------------------------------------
       
  1778 CMPXSeekingState::~CMPXSeekingState()
       
  1779 {
       
  1780     MPX_DEBUG(_L("CMPXSeekingState::~CMPXSeekingState()"));
       
  1781 }
       
  1782 
       
  1783 //  ------------------------------------------------------------------------------------------------
       
  1784 //  CMPXSeekingState::HandlePlay()
       
  1785 //  ------------------------------------------------------------------------------------------------
       
  1786 void CMPXSeekingState::HandlePlay()
       
  1787 {
       
  1788     MPX_DEBUG(_L("CMPXSeekingState::HandlePlay()"));
       
  1789 
       
  1790     if ( iVideoPlaybackCtlr->iPlaybackMode->CanPlayNow() )
       
  1791     {
       
  1792         iVideoPlaybackCtlr->iPlayer->Play();
       
  1793 
       
  1794         iVideoPlaybackCtlr->ChangeState( EMPXVideoPlaying );
       
  1795 
       
  1796         iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPPlaying,
       
  1797                                                               0,
       
  1798                                                               KErrNone );
       
  1799     }
       
  1800     else
       
  1801     {
       
  1802         iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
       
  1803     }
       
  1804 }
       
  1805 
       
  1806 //  ------------------------------------------------------------------------------------------------
       
  1807 //    CMPXSeekingState::HandleBackground()
       
  1808 //  ------------------------------------------------------------------------------------------------
       
  1809 void CMPXSeekingState::HandleBackground()
       
  1810 {
       
  1811     MPX_DEBUG(_L("CMPXSeekingState::HandleBackground()"));
       
  1812     MPX_TRAPD( err, iVideoPlaybackCtlr->iState->HandleStopSeekL() );
       
  1813     iVideoPlaybackCtlr->iPlaybackMode->HandleBackground();
       
  1814 }
       
  1815 
       
  1816 //  ------------------------------------------------------------------------------------------------
       
  1817 //  CMPXSeekingState::HandlePause()
       
  1818 //  ------------------------------------------------------------------------------------------------
       
  1819 void CMPXSeekingState::HandlePause()
       
  1820 {
       
  1821     MPX_DEBUG(_L("CMPXSeekingState::HandlePause()"));
       
  1822     iVideoPlaybackCtlr->iPlaybackMode->HandlePause();
       
  1823 }
       
  1824 
       
  1825 //  ------------------------------------------------------------------------------------------------
       
  1826 //  CMPXSeekingState::HandleStopSeekL()
       
  1827 //  ------------------------------------------------------------------------------------------------
       
  1828 void CMPXSeekingState::HandleStopSeekL()
       
  1829 {
       
  1830     MPX_ENTER_EXIT(_L("CMPXSeekingState::HandleStopSeekL()"));
       
  1831 
       
  1832     iVideoPlaybackCtlr->iVideoSeeker->StopSeekingL();
       
  1833 }
       
  1834 
       
  1835 //  ------------------------------------------------------------------------------------------------
       
  1836 //  CMPXSeekingState::HandleSetPositionL()
       
  1837 //  ------------------------------------------------------------------------------------------------
       
  1838 void CMPXSeekingState::HandleSetPositionL( TInt aPosition )
       
  1839 {
       
  1840     MPX_ENTER_EXIT(_L("CMPXSeekingState::HandleSetPositionL()"),
       
  1841                    _L("position = %d"), aPosition );
       
  1842 
       
  1843     if ( iVideoPlaybackCtlr->iFileDetails->iSeekable )
       
  1844     {
       
  1845         TInt64 pos( aPosition );
       
  1846 
       
  1847         pos *= KPbMilliMultiplier;
       
  1848 
       
  1849         iVideoPlaybackCtlr->iPlayer->SetPositionL( pos );
       
  1850     }
       
  1851     else
       
  1852     {
       
  1853         MPX_DEBUG(_L("CMPXSeekingState::HandleSetPosition() FAIL - file is not seekable"));
       
  1854     }
       
  1855 }
       
  1856 
       
  1857 //  ------------------------------------------------------------------------------------------------
       
  1858 //  CMPXSeekingState::HandleStop()
       
  1859 //  ------------------------------------------------------------------------------------------------
       
  1860 void CMPXSeekingState::HandleStop()
       
  1861 {
       
  1862     MPX_ENTER_EXIT(_L("CMPXSeekingState::HandleStop()"));
       
  1863 
       
  1864     iVideoPlaybackCtlr->iPlayer->Stop();
       
  1865 
       
  1866     iVideoPlaybackCtlr->ChangeState( EMPXVideoStopped );
       
  1867 
       
  1868     iVideoPlaybackCtlr->iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPStopped,
       
  1869                                                           0,
       
  1870                                                           KErrNone );
       
  1871 }
       
  1872 
       
  1873 // End of file