videoplayback/hbvideoplaybackview/viewsrc/mpxvideoviewwrapper.cpp
changeset 15 cf5481c2bc0b
child 17 69946d1824c4
equal deleted inserted replaced
2:dec420019252 15:cf5481c2bc0b
       
     1 /*
       
     2 * Copyright (c) 2009 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:   Implementation of Video base playback view
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: da1mmcf#24 %
       
    19 
       
    20 
       
    21 
       
    22 //  Include Files
       
    23 
       
    24 #include <w32std.h>
       
    25 #include <eikenv.h>
       
    26 
       
    27 #include <mpxplaybackcommanddefs.h>
       
    28 #include <mpxvideoplaybackdefs.h>
       
    29 #include <mpxcommandgeneraldefs.h>
       
    30 #include <mpxcommand.h>
       
    31 #include <mpxmessagegeneraldefs.h>
       
    32 #include <mpxplaybackmessage.h>
       
    33 #include <mpxmediageneraldefs.h>
       
    34 #include <mpxmediavideodefs.h>
       
    35 #include <mpxplaybackutility.h>
       
    36 #include <mmf/common/mmferrors.h>
       
    37 #include <mpxcollectionutility.h>
       
    38 #include <mpxcollectionplaylist.h>
       
    39 #include <mpxmediageneralextdefs.h>
       
    40 
       
    41 #include "mpxvideo_debug.h"
       
    42 #include "mpxvideoregion.h"
       
    43 #include "mpxvideoviewwrapper.h"
       
    44 #include "mpxvideoplaybackuids.hrh"
       
    45 #include "mpxhbvideocommondefs.h"
       
    46 #include "hbvideobaseplaybackview.h"
       
    47 #include "mpxvideoplaybackcontrol.hrh"
       
    48 #include "mpxvideoplaybackviewfiledetails.h"
       
    49 #include "mpxvideoplaybackdisplayhandler.h"
       
    50 #include "mpxcommonvideoplaybackview.hrh"
       
    51 #include "mpxvideoplaybackcontrolscontroller.h"
       
    52 #include "mpxvideoplaybackuserinputhandler.h"
       
    53 
       
    54 //  Member Functions
       
    55 
       
    56 // -------------------------------------------------------------------------------------------------
       
    57 // CMPXVideoViewWrapper::CMPXVideoViewWrapper()
       
    58 // -------------------------------------------------------------------------------------------------
       
    59 //
       
    60 CMPXVideoViewWrapper::CMPXVideoViewWrapper( HbVideoBasePlaybackView* aView )
       
    61     : iView( aView )
       
    62     , iControlsController( NULL )
       
    63     , iMediaRequested( false )
       
    64     , iPlaylistView( false )
       
    65 {
       
    66 }
       
    67 
       
    68 // -------------------------------------------------------------------------------------------------
       
    69 // CMPXVideoViewWrapper::NewL()
       
    70 // -------------------------------------------------------------------------------------------------
       
    71 //
       
    72 CMPXVideoViewWrapper* CMPXVideoViewWrapper::NewL( HbVideoBasePlaybackView* aView )
       
    73 {
       
    74     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::NewL()"));
       
    75 
       
    76     CMPXVideoViewWrapper* self = new (ELeave) CMPXVideoViewWrapper( aView );
       
    77 
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop();
       
    81 
       
    82     return self;
       
    83 }
       
    84 
       
    85 // -------------------------------------------------------------------------------------------------
       
    86 //   CMPXVideoViewWrapper::ConstructL()
       
    87 // -------------------------------------------------------------------------------------------------
       
    88 //
       
    89 void CMPXVideoViewWrapper::ConstructL()
       
    90 {
       
    91     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::ConstructL()"));
       
    92 
       
    93     iPlaybackUtility = 
       
    94         MMPXPlaybackUtility::UtilityL( EMPXCategoryVideo, KPbModeDefault );
       
    95     iPlaybackUtility->AddObserverL( *this );
       
    96     iPlaybackUtility->SetPrimaryClientL();
       
    97 
       
    98     //
       
    99     //  Create Active Object for closing player
       
   100     //
       
   101     iCloseAO = CIdle::NewL( CActive::EPriorityStandard );   
       
   102                 
       
   103     //
       
   104     //  Create Video Playback Display Handler
       
   105     //
       
   106     iDisplayHandler = CMPXVideoPlaybackDisplayHandler::NewL( iPlaybackUtility, this );
       
   107 
       
   108     //
       
   109     // Create control's controller
       
   110     //
       
   111     CreateControlsL();
       
   112 
       
   113     //
       
   114     // Create user input handler
       
   115     //
       
   116     iUserInputHandler = CMPXVideoPlaybackUserInputHandler::NewL( this, iFileDetails->mTvOutConnected );
       
   117 }
       
   118 
       
   119 // -------------------------------------------------------------------------------------------------
       
   120 // CMPXVideoViewWrapper::~CMPXVideoViewWrapper()
       
   121 // -------------------------------------------------------------------------------------------------
       
   122 //
       
   123 CMPXVideoViewWrapper::~CMPXVideoViewWrapper()
       
   124 {
       
   125     MPX_DEBUG(_L("CMPXVideoViewWrapper::~CMPXVideoViewWrapper()"));
       
   126 
       
   127     //
       
   128     //  Delete the display handler when the view is deactivated
       
   129     //
       
   130     if ( iDisplayHandler )
       
   131     {
       
   132         iDisplayHandler->RemoveDisplayWindow();
       
   133         delete iDisplayHandler;
       
   134         iDisplayHandler = NULL;
       
   135     }
       
   136 
       
   137     if ( iUserInputHandler )
       
   138     {
       
   139         delete iUserInputHandler;
       
   140         iUserInputHandler = NULL;
       
   141     }
       
   142 
       
   143     if ( iControlsController )
       
   144     {
       
   145         delete iControlsController;
       
   146         iControlsController = NULL;
       
   147     }
       
   148 
       
   149     if ( iCloseAO )
       
   150     {
       
   151         delete iCloseAO;
       
   152         iCloseAO = NULL;
       
   153     }
       
   154 
       
   155     if ( iFileDetails )
       
   156     {
       
   157         delete iFileDetails;
       
   158         iFileDetails = NULL;
       
   159     }
       
   160 
       
   161     if ( iPlaybackUtility )
       
   162     {
       
   163         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
       
   164         iPlaybackUtility->Close();
       
   165         iPlaybackUtility = NULL;
       
   166     }
       
   167 
       
   168     if ( iCollectionUtility )
       
   169     {
       
   170         iCollectionUtility->Close();
       
   171     }
       
   172 }
       
   173 
       
   174 // -------------------------------------------------------------------------------------------------
       
   175 // CMPXVideoViewWrapper::IsLive()
       
   176 // -------------------------------------------------------------------------------------------------
       
   177 //
       
   178 TBool CMPXVideoViewWrapper::IsLive()
       
   179 {
       
   180     return (iFileDetails->mPlaybackMode == EMPXVideoLiveStreaming);
       
   181 }
       
   182 
       
   183 // -------------------------------------------------------------------------------------------------
       
   184 // CMPXVideoViewWrapper::IsPlaylist()
       
   185 // -------------------------------------------------------------------------------------------------
       
   186 //
       
   187 TBool CMPXVideoViewWrapper::IsPlaylist()
       
   188 {
       
   189     return iPlaylistView;
       
   190 }
       
   191 
       
   192 // -------------------------------------------------------------------------------------------------
       
   193 //   CMPXVideoViewWrapper::CreateGeneralPlaybackCommandL()
       
   194 // -------------------------------------------------------------------------------------------------
       
   195 //
       
   196 void CMPXVideoViewWrapper::CreateGeneralPlaybackCommandL( TMPXPlaybackCommand aCmd )
       
   197 {
       
   198     MPX_DEBUG(_L("CMPXVideoViewWrapper::CreateGeneralPlaybackCommandL(%d)"), aCmd );
       
   199 
       
   200     CMPXCommand* cmd = CMPXCommand::NewL();
       
   201     CleanupStack::PushL( cmd );
       
   202 
       
   203     cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
   204     cmd->SetTObjectValueL<TBool>( KMPXCommandPlaybackGeneralNoBuffer, ETrue );
       
   205     cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXCommandIdPlaybackGeneral );
       
   206     cmd->SetTObjectValueL<TInt>( KMPXCommandPlaybackGeneralType, aCmd );
       
   207 
       
   208     iPlaybackUtility->CommandL( *cmd );
       
   209 
       
   210     CleanupStack::PopAndDestroy( cmd );
       
   211 }
       
   212 
       
   213 // -------------------------------------------------------------------------------------------------
       
   214 //   CMPXVideoViewWrapper::HandleCommandL()
       
   215 // -------------------------------------------------------------------------------------------------
       
   216 //
       
   217 void CMPXVideoViewWrapper::HandleCommandL( TInt aCommand )
       
   218 {
       
   219     MPX_ENTER_EXIT(
       
   220         _L("CMPXVideoViewWrapper::HandleCommandL()"),
       
   221         _L("aCommand = %d"), aCommand );
       
   222 
       
   223     switch ( aCommand )
       
   224     {
       
   225         case EMPXPbvCmdPlay:
       
   226         {
       
   227             IssuePlayCommandL();
       
   228             break;
       
   229         }
       
   230         case EMPXPbvCmdPause:
       
   231         {
       
   232             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdPause"));
       
   233             CreateGeneralPlaybackCommandL( EPbCmdPause );
       
   234             break;
       
   235         }
       
   236         case EMPXPbvCmdClose:
       
   237         {
       
   238             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdClose"));
       
   239             
       
   240             //
       
   241             // The display window must be removed before closing the playback plugin
       
   242             //
       
   243             if ( iDisplayHandler )
       
   244             {
       
   245                 //
       
   246                 // Remove the display window so the surface can be released
       
   247                 //
       
   248                 iDisplayHandler->RemoveDisplayWindow();
       
   249             }
       
   250 
       
   251             CreateGeneralPlaybackCommandL( EPbCmdClose );
       
   252             break;
       
   253         }
       
   254         case EMPXPbvCmdSeekForward:
       
   255         {
       
   256             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdSeekForward"));
       
   257             CreateVideoSpecificCmdL( EPbCmdStartVideoSeekingForward );
       
   258             break;
       
   259         }
       
   260         case EMPXPbvCmdSeekBackward:
       
   261         {
       
   262             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdSeekBackward"));
       
   263             CreateVideoSpecificCmdL( EPbCmdStartVideoSeekingBackward );
       
   264             break;
       
   265         }
       
   266         case EMPXPbvCmdEndSeek:
       
   267         {
       
   268             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdEndSeek"));
       
   269             CreateVideoSpecificCmdL( EPbCmdStopVideoSeeking );
       
   270             break;
       
   271         }
       
   272         case EMPXPbvCmdPlayPause:
       
   273         {
       
   274             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdPause"));
       
   275             iPlaybackUtility->CommandL( EPbCmdPlayPause );
       
   276             break;
       
   277         }
       
   278         case EMPXPbvCmdStop:
       
   279         {
       
   280             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdStop"));
       
   281             CreateGeneralPlaybackCommandL( EPbCmdStop );
       
   282             break;
       
   283         }
       
   284         case EMPXPbvCmdDecreaseVolume:
       
   285         {
       
   286             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdDecreaseVolume"));
       
   287             HandleVolumeCmdL( EPbCmdDecreaseVolume );
       
   288             break;
       
   289         }
       
   290         case EMPXPbvCmdIncreaseVolume:
       
   291         {
       
   292             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdIncreaseVolume"));
       
   293             HandleVolumeCmdL( EPbCmdIncreaseVolume );
       
   294             break;
       
   295         }
       
   296         case EMPXPbvCmdNaturalAspectRatio:
       
   297         {
       
   298             MPX_DEBUG(
       
   299                 _L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdNaturalAspectRatio"));
       
   300             SetAspectRatioL( EPbCmdNaturalAspectRatio );
       
   301             break;
       
   302         }
       
   303         case EMPXPbvCmdZoomAspectRatio:
       
   304         {
       
   305             MPX_DEBUG(
       
   306                 _L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdZoomAspectRatio"));
       
   307             SetAspectRatioL( EPbCmdZoomAspectRatio );
       
   308             break;
       
   309         }
       
   310         case EMPXPbvCmdStretchAspectRatio:
       
   311         {
       
   312             MPX_DEBUG(
       
   313                 _L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdStretchAspectRatio"));
       
   314             SetAspectRatioL( EPbCmdStretchAspectRatio );
       
   315             break;
       
   316         }
       
   317         case EMPXPbvCmdMute:
       
   318         {
       
   319             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdMute"));
       
   320             HandleVolumeCmdL( EPbCmdMuteVolume );
       
   321             break;
       
   322         }
       
   323         case EMPXPbvCmdUnMute:
       
   324         {
       
   325             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdUnMute"));
       
   326             HandleVolumeCmdL( EPbCmdUnMuteVolume );
       
   327             break;
       
   328         }
       
   329         case EMPXPbvCmdShortPressBackward:
       
   330         {
       
   331             MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL() EMPXPbvCmdShortPressBackward"));
       
   332 
       
   333             HandleShortPressBackwardL();
       
   334             break;
       
   335         }
       
   336         case EMPXPbvCmdResetControls:
       
   337         {
       
   338             CreateControlsL();
       
   339             iView->retrievePdlInformation();
       
   340             break;
       
   341         }
       
   342         case EMPXPbvCmdNextListItem:
       
   343         {
       
   344             if ( iPlaylistView && iFileDetails->mMultiItemPlaylist )
       
   345             {
       
   346                 iPlaybackUtility->CommandL( EPbCmdNext );
       
   347             }
       
   348             break;
       
   349         }
       
   350         case EMPXPbvCmdPreviousListItem:  
       
   351         {
       
   352             if ( iPlaylistView && iFileDetails->mMultiItemPlaylist )
       
   353             {
       
   354 			    //
       
   355 			    // the command is being sent twice on purpose
       
   356                 // one EMPXPbvCmdPreviousListItem command only sets the position to 0  
       
   357                 // the second cmd actually goes to the previous item in the list
       
   358 				//
       
   359                 iPlaybackUtility->CommandL( EPbCmdPrevious );
       
   360                 iPlaybackUtility->CommandL( EPbCmdPrevious );  
       
   361             }
       
   362             break;
       
   363         }
       
   364         case EMPXPbvCmdEndOfClip:
       
   365         {
       
   366             CreateVideoSpecificCmdL( EPbCmdEndofClipReached );
       
   367             break;
       
   368         }
       
   369         case EMPXPbvCmdCustomPause:
       
   370         {
       
   371             CreateVideoSpecificCmdL( EPbCmdCustomPause );
       
   372             break;
       
   373         }
       
   374         case EMPXPbvCmdCustomPlay:
       
   375         {
       
   376             CreateVideoSpecificCmdL( EPbCmdCustomPlay );
       
   377             break;
       
   378         }
       
   379     }
       
   380 }
       
   381 
       
   382 // -------------------------------------------------------------------------------------------------
       
   383 // From MMPXPlaybackObserver
       
   384 // Handle playback message.
       
   385 // -------------------------------------------------------------------------------------------------
       
   386 //
       
   387 void CMPXVideoViewWrapper::HandlePlaybackMessage( CMPXMessage* aMessage, TInt aError )
       
   388 {
       
   389     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::HandlePlaybackMessage()"),
       
   390                    _L("aError = %d"), aError );
       
   391 
       
   392     if ( aError )
       
   393     {
       
   394         MPX_TRAPD( err, DoHandleErrorPlaybackMessageL( aError ) );
       
   395     }
       
   396     else if ( aMessage )
       
   397     {
       
   398         MPX_TRAPD( err, DoHandlePlaybackMessageL( aMessage ) );
       
   399     }
       
   400 }
       
   401 
       
   402 // -------------------------------------------------------------------------------------------------
       
   403 // Request for the media object
       
   404 // -------------------------------------------------------------------------------------------------
       
   405 //
       
   406 void CMPXVideoViewWrapper::RequestMediaL()
       
   407 {
       
   408     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::RequestMediaL()"));
       
   409 
       
   410     if ( ! iMediaRequested && iPlaybackUtility->StateL() == EPbStateInitialised )
       
   411     {
       
   412         iMediaRequested = ETrue;
       
   413 
       
   414         //
       
   415         //  Request the volume for the controls
       
   416         //
       
   417         iPlaybackUtility->PropertyL( *this, EPbPropertyVolume );
       
   418 
       
   419         //
       
   420         //  Request the clip's meta data
       
   421         //
       
   422         MMPXSource* s = iPlaybackUtility->Source();
       
   423 
       
   424         if ( s )
       
   425         {
       
   426             RArray<TMPXAttribute> attrs;
       
   427             CleanupClosePushL(attrs);
       
   428 
       
   429             //
       
   430             //  General Media Attributes
       
   431             //
       
   432             attrs.Append( KMPXMediaGeneralUri |
       
   433                           KMPXMediaGeneralDuration |
       
   434                           KMPXMediaGeneralTitle |
       
   435                           KMPXMediaGeneralMimeType );
       
   436 
       
   437             //
       
   438             //  Video specific Attributes
       
   439             //
       
   440             attrs.Append( KMPXMediaVideoAll );
       
   441 
       
   442             // Set the attribute to always route the media call to playback plugin
       
   443             CMPXAttributeSpecs* specs = CMPXAttributeSpecs::NewL();
       
   444             CleanupStack::PushL( specs );
       
   445 
       
   446             specs->SetTObjectValueL<TBool>(KMPXMediaGeneralExtMediaRedirect, ETrue);
       
   447 
       
   448             s->MediaL( attrs.Array(), *this, specs);
       
   449 
       
   450             CleanupStack::PopAndDestroy( specs );
       
   451             CleanupStack::PopAndDestroy( &attrs );
       
   452         }
       
   453     }
       
   454 }
       
   455 
       
   456 // -------------------------------------------------------------------------------------------------
       
   457 //   CMPXVideoViewWrapper::DoHandlePlaybackMessageL()
       
   458 // -------------------------------------------------------------------------------------------------
       
   459 //
       
   460 void CMPXVideoViewWrapper::DoHandlePlaybackMessageL( CMPXMessage* aMessage )
       
   461 {
       
   462     TMPXMessageId id( *(aMessage->Value<TMPXMessageId>(KMPXMessageGeneralId)) );
       
   463 
       
   464     MPX_ENTER_EXIT(
       
   465         _L("CMPXVideoViewWrapper::DoHandlePlaybackMessageL()"),
       
   466         _L("id = 0x%08x"), id );
       
   467 
       
   468     if ( KMPXMessageGeneral == id )
       
   469     {
       
   470         HandleGeneralPlaybackMessageL( aMessage );
       
   471     }
       
   472     else if ( KMPXMediaIdVideoPlayback == id )
       
   473     {
       
   474         HandleVideoPlaybackMessage( aMessage );
       
   475     }
       
   476     else if ( KMPXMediaIdVideoDisplaySyncMessage == id )
       
   477     {
       
   478         if ( iDisplayHandler )
       
   479         {
       
   480             iDisplayHandler->HandleVideoDisplayMessageL( aMessage );
       
   481         }
       
   482 
       
   483         //
       
   484         //  Signal Sync Message handling is complete
       
   485         //
       
   486         iPlaybackUtility->CommandL( EPbCmdSyncMsgComplete );
       
   487     }
       
   488 }
       
   489 
       
   490 // -------------------------------------------------------------------------------------------------
       
   491 //   CMPXVideoViewWrapper::HandleGeneralPlaybackMessageL()
       
   492 // -------------------------------------------------------------------------------------------------
       
   493 //
       
   494 void CMPXVideoViewWrapper::HandleGeneralPlaybackMessageL( CMPXMessage* aMessage )
       
   495 {
       
   496     TInt event( *aMessage->Value<TInt>( KMPXMessageGeneralEvent ) );
       
   497     TInt type( *aMessage->Value<TInt>( KMPXMessageGeneralType ) );
       
   498     TInt data( *aMessage->Value<TInt>( KMPXMessageGeneralData ) );
       
   499 
       
   500     MPX_DEBUG(
       
   501       _L("CMPXVideoViewWrapper::HandleGeneralPlaybackMessageL() event = %d type = %d  value = %d"),
       
   502       event, type, data );
       
   503 
       
   504     switch ( event )
       
   505     {
       
   506         case TMPXPlaybackMessage::EStateChanged:
       
   507         {
       
   508             DoHandleStateChangeL( type );
       
   509 
       
   510             break;
       
   511         }
       
   512         case TMPXPlaybackMessage::EPropertyChanged:
       
   513         {
       
   514             TMPXPlaybackProperty property(
       
   515                  static_cast<TMPXPlaybackProperty>( type ) );
       
   516 
       
   517             HandlePropertyL( property, data, KErrNone );
       
   518             break;
       
   519         }
       
   520         case TMPXPlaybackMessage::EDownloadPositionChanged:
       
   521         {
       
   522             if ( iControlsController )
       
   523             {
       
   524                 iControlsController->handleEvent( EMPXControlCmdDownloadUpdated, data );
       
   525             }
       
   526 
       
   527             break;
       
   528         }
       
   529         case TMPXPlaybackMessage::EDownloadStateChanged:
       
   530         {
       
   531             break;
       
   532         }
       
   533         case TMPXPlaybackMessage::ECommandReceived:
       
   534         {
       
   535             break;
       
   536         }
       
   537         case TMPXPlaybackMessage::EReachedEndOfPlaylist:
       
   538         {
       
   539             iView->closePlaybackView();
       
   540             break;
       
   541         }
       
   542         case TMPXPlaybackMessage::ESongChanged:
       
   543         {
       
   544             break;
       
   545         }
       
   546     }
       
   547 }
       
   548 
       
   549 // -------------------------------------------------------------------------------------------------
       
   550 //   CMPXVideoViewWrapper::HandleVideoPlaybackMessage()
       
   551 // -------------------------------------------------------------------------------------------------
       
   552 //
       
   553 void CMPXVideoViewWrapper::HandleVideoPlaybackMessage( CMPXMessage* aMessage )
       
   554 {
       
   555     TMPXVideoPlaybackCommand message =
       
   556         ( *(aMessage->Value<TMPXVideoPlaybackCommand>(KMPXMediaVideoPlaybackCommand)) );
       
   557 
       
   558     MPX_DEBUG(
       
   559       _L("CMPXVideoViewWrapper::HandleVideoPlaybackMessage() message = %d"), message );
       
   560 
       
   561     switch ( message )
       
   562     {
       
   563         case EPbCmdPluginError:
       
   564         {
       
   565             TInt error( *aMessage->Value<TInt>( KMPXMediaVideoError ) );
       
   566 
       
   567             iView->handlePluginError( error );
       
   568             break;
       
   569         }
       
   570         case EPbCmdTvOutEvent:
       
   571         {
       
   572             TMPXVideoPlaybackControlCommandIds cmdId = EMPXControlCmdTvOutDisconnected;
       
   573 
       
   574             TBool tvOutConnected( *aMessage->Value<TInt>( KMPXMediaVideoTvOutConnected ) );
       
   575             TBool playbackAllowed = ETrue;
       
   576 
       
   577             if ( tvOutConnected )
       
   578             {
       
   579                 cmdId = EMPXControlCmdTvOutConnected;
       
   580 
       
   581                 playbackAllowed = *aMessage->Value<TInt>( KMPXMediaVideoTvOutPlayAllowed );
       
   582             }
       
   583 
       
   584             if ( iUserInputHandler )
       
   585             {
       
   586                 TRAP_IGNORE(iUserInputHandler->HandleTVOutEventL( tvOutConnected ));     
       
   587             }
       
   588 
       
   589             if ( iControlsController )
       
   590             {
       
   591                 iControlsController->handleEvent( cmdId, playbackAllowed );
       
   592             }
       
   593             break;
       
   594         }
       
   595     }
       
   596 }
       
   597 
       
   598 // -------------------------------------------------------------------------------------------------
       
   599 //   CMPXVideoViewWrapper::HandlePluginError()
       
   600 // -------------------------------------------------------------------------------------------------
       
   601 //
       
   602 void CMPXVideoViewWrapper::HandlePluginError( int aError )
       
   603 {
       
   604     MPX_DEBUG(
       
   605       _L("CMPXVideoViewWrapper::HandlePluginError() aError = %d"), aError );
       
   606 
       
   607     iView->handlePluginError( aError );
       
   608 }
       
   609 
       
   610 // -------------------------------------------------------------------------------------------------
       
   611 //   Handle playback state changes
       
   612 // -------------------------------------------------------------------------------------------------
       
   613 //
       
   614 void CMPXVideoViewWrapper::DoHandleStateChangeL( TInt aNewState )
       
   615 {
       
   616     MPX_ENTER_EXIT(
       
   617         _L("CMPXVideoViewWrapper::DoHandleStateChangeL()"),
       
   618         _L("aNewState = %d"), aNewState );
       
   619 
       
   620     if ( aNewState != iPlaybackState )
       
   621     {
       
   622         switch ( aNewState )
       
   623         {
       
   624             case EPbStateInitialising:
       
   625             {
       
   626                 if ( iControlsController )
       
   627                 {
       
   628                     //
       
   629                     //  If transitioning from Not Initialized to Initialising there is
       
   630                     //  no need to update the playback information that was gathered
       
   631                     //  when the container was created
       
   632                     //
       
   633                     if ( iPlaybackState != EPbStateNotInitialised )
       
   634                     {
       
   635                         iMediaRequested = EFalse;
       
   636                         HandleCommandL( EMPXPbvCmdResetControls );
       
   637 
       
   638                         if ( iFileDetails )
       
   639                         {    
       
   640                             iFileDetails->clearFileDetails();
       
   641                         }
       
   642                     }
       
   643                 }
       
   644                 break;
       
   645             }
       
   646             case EPbStateBuffering:
       
   647             {
       
   648                 HandleBufferingStateL();
       
   649 
       
   650                 break;
       
   651             }
       
   652             case EPbStatePluginSeeking:
       
   653             {
       
   654                 // no-op
       
   655                 break;
       
   656             }
       
   657             case EPbStateStopped:
       
   658             {
       
   659                 if ( iPlaylistView && iDisplayHandler )
       
   660                 {
       
   661                     iDisplayHandler->RemoveDisplayWindow();
       
   662                 }
       
   663 
       
   664                 if ( iFileDetails->mMultiItemPlaylist )
       
   665                 {
       
   666                     iView->handleStoppedState();
       
   667                 }
       
   668                 else
       
   669                 {
       
   670                     iView->closePlaybackView();  
       
   671                 }
       
   672 
       
   673                 break;
       
   674             }
       
   675             case EPbStateInitialised:
       
   676             {
       
   677                 RequestMediaL();
       
   678             	break;
       
   679             }
       
   680             default:
       
   681             {
       
   682                 break;
       
   683             }
       
   684         }
       
   685 
       
   686         iPlaybackState = (TMPXPlaybackState)aNewState;
       
   687 
       
   688         if ( iControlsController )
       
   689         {
       
   690             iControlsController->handleEvent( EMPXControlCmdStateChanged, aNewState );
       
   691         }
       
   692     }
       
   693 }
       
   694 
       
   695 // -------------------------------------------------------------------------------------------------
       
   696 //   CMPXVideoViewWrapper::HandleBufferingStateL
       
   697 // -------------------------------------------------------------------------------------------------
       
   698 //
       
   699 void CMPXVideoViewWrapper::HandleBufferingStateL()
       
   700 {
       
   701     MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleBufferingStateL()"));
       
   702 
       
   703 }
       
   704 
       
   705 // -------------------------------------------------------------------------------------------------
       
   706 // Handle playback error message.
       
   707 // -------------------------------------------------------------------------------------------------
       
   708 //
       
   709 void CMPXVideoViewWrapper::DoHandleErrorPlaybackMessageL( TInt aError )
       
   710 {
       
   711     MPX_ENTER_EXIT( _L("CMPXVideoViewWrapper::DoHandleErrorPlaybackMessageL()"),
       
   712                     _L("aError = %d"), aError );
       
   713 
       
   714     HandleCommandL( EMPXPbvCmdResetControls );
       
   715     iView->handlePluginError(aError);
       
   716 }
       
   717 
       
   718 // -------------------------------------------------------------------------------------------------
       
   719 // CMPXVideoViewWrapper::HandlePlaybackCommandComplete()
       
   720 // -------------------------------------------------------------------------------------------------
       
   721 //
       
   722 void CMPXVideoViewWrapper::HandlePlaybackCommandComplete( CMPXCommand* /*aCommandResult*/,
       
   723                                                          TInt /*aError*/ )
       
   724 {
       
   725     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::HandlePlaybackCommandComplete()"));
       
   726 }
       
   727 
       
   728 // -------------------------------------------------------------------------------------------------
       
   729 // CMPXVideoViewWrapper::ParseMetaDataL()
       
   730 // -------------------------------------------------------------------------------------------------
       
   731 //
       
   732 void CMPXVideoViewWrapper::ParseMetaDataL( const CMPXMessage& aMedia )
       
   733 {
       
   734     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::ParseMetaDataL()"));
       
   735 
       
   736     //
       
   737     //  Clip Name
       
   738     //
       
   739     if ( aMedia.IsSupported( KMPXMediaGeneralUri ) )
       
   740     {
       
   741         TPtrC uri( aMedia.ValueText( KMPXMediaGeneralUri ) );
       
   742         const QString qClipname( (QChar*)uri.Ptr(), uri.Length() );
       
   743         iFileDetails->mClipName = qClipname;
       
   744     }
       
   745 
       
   746     //
       
   747     //  Title
       
   748     //
       
   749     if ( aMedia.IsSupported( KMPXMediaGeneralTitle ) )
       
   750     {
       
   751         TPtrC title( aMedia.ValueText( KMPXMediaGeneralTitle ) );
       
   752         const QString qTitle( (QChar*)title.Ptr(), title.Length() );
       
   753         iFileDetails->mTitle = qTitle;
       
   754     }
       
   755 
       
   756     //
       
   757     //  Artist
       
   758     //
       
   759     if ( aMedia.IsSupported( KMPXMediaVideoArtist ) )
       
   760     {
       
   761         TPtrC artist( aMedia.ValueText( KMPXMediaVideoArtist ) );
       
   762         const QString qArtist( (QChar*)artist.Ptr(), artist.Length() );
       
   763         iFileDetails->mArtist = qArtist;
       
   764     }
       
   765 
       
   766     //
       
   767     //  Mime Type
       
   768     //
       
   769     if ( aMedia.IsSupported( KMPXMediaGeneralMimeType ) )
       
   770     {
       
   771         TPtrC mimeType( aMedia.ValueText( KMPXMediaGeneralMimeType ) );
       
   772         const QString qMimeType( (QChar*)mimeType.Ptr(), mimeType.Length() );
       
   773         iFileDetails->mMimeType = qMimeType;
       
   774     }
       
   775 
       
   776     //
       
   777     //  Duration
       
   778     //
       
   779     if ( aMedia.IsSupported( KMPXMediaGeneralDuration ) )
       
   780     {
       
   781         iFileDetails->mDuration = aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralDuration );
       
   782     }
       
   783 
       
   784     //
       
   785     //  Audio Enabled
       
   786     //
       
   787     if ( aMedia.IsSupported( KMPXMediaVideoAudioEnabled ) )
       
   788     {
       
   789         iFileDetails->mAudioEnabled = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoAudioEnabled );
       
   790     }
       
   791 
       
   792     //
       
   793     //  Video Enabled
       
   794     //
       
   795     if ( aMedia.IsSupported( KMPXMediaVideoVideoEnabled ) )
       
   796     {
       
   797         iFileDetails->mVideoEnabled = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoVideoEnabled );
       
   798     }
       
   799 
       
   800     //
       
   801     //  Partial Playback
       
   802     //
       
   803     if ( aMedia.IsSupported( KMPXMediaVideoPartialPlayback ) )
       
   804     {
       
   805         iFileDetails->mPartialPlayback =
       
   806             aMedia.ValueTObjectL<TInt>( KMPXMediaVideoPartialPlayback );
       
   807     }
       
   808 
       
   809     //
       
   810     //  Playback Mode
       
   811     //
       
   812     if ( aMedia.IsSupported( KMPXMediaVideoPlaybackMode ) )
       
   813     {
       
   814         iFileDetails->mPlaybackMode =
       
   815             (TMPXVideoMode)aMedia.ValueTObjectL<TInt>( KMPXMediaVideoPlaybackMode );
       
   816     }
       
   817 
       
   818     //
       
   819     //  Seekable
       
   820     //
       
   821     if ( aMedia.IsSupported( KMPXMediaVideoSeekable ) )
       
   822     {
       
   823         iFileDetails->mSeekable = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoSeekable );
       
   824     }
       
   825 
       
   826     //
       
   827     //  Pausable
       
   828     //
       
   829     if ( aMedia.IsSupported( KMPXMediaVideoPausableStream ) )
       
   830     {
       
   831         iFileDetails->mPausableStream = aMedia.ValueTObjectL<TBool>( KMPXMediaVideoPausableStream );
       
   832     }
       
   833 
       
   834     //
       
   835     //  Video Height
       
   836     //
       
   837     if ( aMedia.IsSupported( KMPXMediaVideoHeight ) )
       
   838     {
       
   839         iFileDetails->mVideoHeight = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoHeight );
       
   840     }
       
   841 
       
   842     //
       
   843     //  Video Width
       
   844     //
       
   845     if ( aMedia.IsSupported( KMPXMediaVideoWidth ) )
       
   846     {
       
   847         iFileDetails->mVideoWidth = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoWidth );
       
   848     }
       
   849 
       
   850     //
       
   851     //  TV-Out Connected
       
   852     //
       
   853     if ( aMedia.IsSupported( KMPXMediaVideoTvOutConnected ) )
       
   854     {
       
   855         iFileDetails->mTvOutConnected = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoTvOutConnected );
       
   856     }
       
   857 
       
   858     //
       
   859     //  TV-Out Playback Allowed
       
   860     //
       
   861     if ( aMedia.IsSupported( KMPXMediaVideoTvOutPlayAllowed ) )
       
   862     {
       
   863         iFileDetails->mTvOutPlayAllowed =
       
   864             aMedia.ValueTObjectL<TInt>( KMPXMediaVideoTvOutPlayAllowed );
       
   865     }
       
   866 
       
   867     //
       
   868     //  BitRate
       
   869     //
       
   870     if ( aMedia.IsSupported( KMPXMediaVideoBitRate ) )
       
   871     {
       
   872         iFileDetails->mBitRate = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoBitRate );
       
   873     }
       
   874 
       
   875     //
       
   876     //  Drm Protected
       
   877     //
       
   878     if ( aMedia.IsSupported( KMPXMediaVideoDrmProtected ) )
       
   879     {
       
   880         iFileDetails->mDrmProtected = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoDrmProtected );
       
   881     }
       
   882     
       
   883     //
       
   884     //  Description
       
   885     //
       
   886     if ( aMedia.IsSupported( KMPXMediaVideoDescription ) )
       
   887     {
       
   888         TPtrC description( aMedia.ValueText( KMPXMediaVideoDescription ) );
       
   889         const QString qDescription( (QChar*)description.Ptr(), description.Length() );
       
   890         iFileDetails->mDescription = qDescription;
       
   891     }
       
   892     
       
   893     //
       
   894     //  Location
       
   895     //
       
   896     if ( aMedia.IsSupported( KMPXMediaVideoLocation ) )
       
   897     {
       
   898         TPtrC location( aMedia.ValueText( KMPXMediaVideoLocation ) );
       
   899         const QString qLocation( (QChar*)location.Ptr(), location.Length() );
       
   900         iFileDetails->mLocation = qLocation;
       
   901     }
       
   902     
       
   903     //
       
   904     //  Copyright
       
   905     //
       
   906     if ( aMedia.IsSupported( KMPXMediaVideoCopyright ) )
       
   907     {
       
   908         TPtrC copyright( aMedia.ValueText( KMPXMediaVideoCopyright ) );
       
   909         const QString qCopyright( (QChar*)copyright.Ptr(), copyright.Length() );
       
   910         iFileDetails->mCopyright = qCopyright;
       
   911     }
       
   912     
       
   913     //
       
   914     //  Language
       
   915     //
       
   916     if ( aMedia.IsSupported( KMPXMediaVideoLanguage ) )
       
   917     {
       
   918         TPtrC language( aMedia.ValueText( KMPXMediaVideoLanguage ) );
       
   919         const QString qLanguage( (QChar*)language.Ptr(), language.Length() );
       
   920         iFileDetails->mLanguage = qLanguage;
       
   921     }
       
   922     
       
   923     //
       
   924     //  Keywords
       
   925     //
       
   926     if ( aMedia.IsSupported( KMPXMediaVideoKeywords ) )
       
   927     {
       
   928         TPtrC keywords( aMedia.ValueText( KMPXMediaVideoKeywords ) );
       
   929         const QString qKeywords( (QChar*)keywords.Ptr(), keywords.Length() );
       
   930         iFileDetails->mKeywords = qKeywords;
       
   931     }
       
   932 }
       
   933 
       
   934 // -------------------------------------------------------------------------------------------------
       
   935 // Handle media properties.
       
   936 // Notes: The client is responsible for delete the object of aProperties.
       
   937 // -------------------------------------------------------------------------------------------------
       
   938 //
       
   939 void CMPXVideoViewWrapper::DoHandleMediaL( const CMPXMessage& aMedia, TInt aError )
       
   940 {
       
   941     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::DoHandleMediaL()"),
       
   942                    _L("aError = %d"), aError );
       
   943 
       
   944     if ( aError == KErrNone )
       
   945     {
       
   946         if ( iFileDetails )
       
   947         {
       
   948             iFileDetails->clearFileDetails();
       
   949         }
       
   950         else
       
   951         {
       
   952             iFileDetails = new QMPXVideoPlaybackViewFileDetails();
       
   953         }       
       
   954         
       
   955         //
       
   956         //  Read in the media data
       
   957         //
       
   958         ParseMetaDataL( aMedia );
       
   959 
       
   960         //
       
   961         //  Create controls since file details are available
       
   962         //
       
   963         if ( iControlsController )
       
   964         {
       
   965             iControlsController->addFileDetails( iFileDetails );            
       
   966         }
       
   967 
       
   968         if ( iFileDetails->mVideoEnabled )
       
   969         {
       
   970             RWindow *window = iView->getWindow();
       
   971 
       
   972             TRect displayRect = TRect( window->Position().iX,
       
   973                                        window->Position().iY,
       
   974                                        window->Position().iX + window->Size().iWidth,                  
       
   975                                        window->Position().iY + window->Size().iHeight );
       
   976 
       
   977             TReal displayAspectRatio = (TReal32)displayRect.Width() / (TReal32)displayRect.Height();
       
   978 
       
   979             TInt newAspectRatio = 
       
   980                 iDisplayHandler->SetDefaultAspectRatioL( iFileDetails, displayAspectRatio );
       
   981 
       
   982             //
       
   983             //  Setup the display window and issue play command
       
   984             //
       
   985             iDisplayHandler->CreateDisplayWindowL( CCoeEnv::Static()->WsSession(),
       
   986                                                    *(CCoeEnv::Static()->ScreenDevice()),
       
   987                                                    *window,
       
   988                                                    displayRect );
       
   989 
       
   990             if ( iControlsController )
       
   991             {
       
   992                 iControlsController->handleEvent( EMPXControlCmdSetAspectRatio, newAspectRatio );
       
   993             }
       
   994         }
       
   995 
       
   996         CreateGeneralPlaybackCommandL( EPbCmdPlay );
       
   997     }
       
   998 }
       
   999 
       
  1000 // -------------------------------------------------------------------------------------------------
       
  1001 // From MMPXPlaybackCallback
       
  1002 // Handle media event.
       
  1003 // Notes: The client is responsible for delete the object of aProperties.
       
  1004 // -------------------------------------------------------------------------------------------------
       
  1005 //
       
  1006 void CMPXVideoViewWrapper::HandleMediaL( const CMPXMedia& aMedia, TInt aError)
       
  1007 {
       
  1008     MPX_ENTER_EXIT(_L( "CMPXVideoViewWrapper::HandleMediaL()" ));
       
  1009     if ( aMedia.IsSupported( KMPXMediaVideoError ) )
       
  1010     {
       
  1011         TInt error = aMedia.ValueTObjectL<TInt>( KMPXMediaVideoError );
       
  1012         // Reset the controls
       
  1013         HandleCommandL( EMPXPbvCmdResetControls );
       
  1014         // Set the iMediaRequested flag to false
       
  1015         iMediaRequested = EFalse;
       
  1016         // Reset the playback state to stopped
       
  1017         iPlaybackState = EPbStateStopped;
       
  1018         // Handle the plugin error
       
  1019         iView->handlePluginError( error );
       
  1020     }
       
  1021     else
       
  1022     {
       
  1023         DoHandleMediaL( aMedia, aError );
       
  1024     }
       
  1025 }
       
  1026 
       
  1027 // -------------------------------------------------------------------------------------------------
       
  1028 //   CMPXVideoViewWrapper::SetPropertyL()
       
  1029 // -------------------------------------------------------------------------------------------------
       
  1030 //
       
  1031 void CMPXVideoViewWrapper::SetPropertyL( TMPXPlaybackProperty aProperty, TInt aValue )
       
  1032 {
       
  1033     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::SetPropertyL"),
       
  1034                    _L("aProperty = %d, aValue = %d"), aProperty, aValue );
       
  1035 
       
  1036     iPlaybackUtility->SetL( aProperty, aValue );
       
  1037 }
       
  1038 
       
  1039 // -------------------------------------------------------------------------------------------------
       
  1040 //   CMPXVideoViewWrapper::HandlePropertyL()
       
  1041 // -------------------------------------------------------------------------------------------------
       
  1042 //
       
  1043 void CMPXVideoViewWrapper::HandlePropertyL( TMPXPlaybackProperty aProperty,
       
  1044                                                  TInt aValue,
       
  1045                                                  TInt aError )
       
  1046 {
       
  1047     MPX_DEBUG(_L("CMPXVideoViewWrapper::DoHandlePropertyL - Error(%d)"), aError );
       
  1048 
       
  1049     if ( aError == KErrNone )
       
  1050     {
       
  1051         switch ( aProperty  )
       
  1052         {
       
  1053             case EPbPropertyPosition:
       
  1054             {
       
  1055                 MPX_DEBUG(_L("CMPXVideoViewWrapper::DoHandlePropertyL position(%d)"), aValue );
       
  1056 
       
  1057                 if ( iControlsController )
       
  1058                 {
       
  1059                     iControlsController->handleEvent( EMPXControlCmdSetPosition, aValue );
       
  1060                 }
       
  1061 
       
  1062                 break;
       
  1063             }
       
  1064             case EPbPropertyDuration:
       
  1065             {
       
  1066                 MPX_DEBUG(_L("CMPXVideoViewWrapper::DoHandlePropertyL duration(%d)"), aValue );
       
  1067 
       
  1068                 if ( iControlsController )
       
  1069                 {
       
  1070                     iControlsController->handleEvent( EMPXControlCmdSetDuration, aValue );
       
  1071                 }
       
  1072 
       
  1073                 break;
       
  1074             }
       
  1075             case EPbPropertyMaxVolume:
       
  1076             {
       
  1077                 MPX_DEBUG(_L("CMPXVideoViewWrapper::DoHandlePropertyL max volume(%d)"), aValue );
       
  1078 
       
  1079                 break;
       
  1080             }
       
  1081             case EPbPropertyVolume:
       
  1082             {
       
  1083                 MPX_DEBUG(_L("CMPXVideoViewWrapper::DoHandlePropertyL volume(%d)"), aValue );
       
  1084 
       
  1085                 if ( iControlsController )
       
  1086                 {
       
  1087                     iControlsController->handleEvent( EMPXControlCmdSetVolume, aValue );
       
  1088                 }
       
  1089 
       
  1090                 break;
       
  1091             }
       
  1092             case EPbPropertyMute:
       
  1093             {
       
  1094                 MPX_DEBUG(_L("CMPXVideoViewWrapper::DoHandlePropertyL mute(%d)"), aValue );
       
  1095 
       
  1096                 if ( iControlsController && aValue )
       
  1097                 {
       
  1098                     iControlsController->handleEvent( EMPXControlCmdSetVolume, 0 );
       
  1099                 }
       
  1100 
       
  1101                 break;
       
  1102             }
       
  1103         }
       
  1104     }
       
  1105 }
       
  1106 
       
  1107 // -------------------------------------------------------------------------------------------------
       
  1108 //   CMPXVideoViewWrapper::RetrieveFileNameAndModeL
       
  1109 // -------------------------------------------------------------------------------------------------
       
  1110 //
       
  1111 void CMPXVideoViewWrapper::RetrieveFileNameAndModeL( CMPXCommand* aCmd )
       
  1112 {
       
  1113     //
       
  1114     //  set attributes on the command
       
  1115     //
       
  1116     aCmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  1117 
       
  1118     aCmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXMediaIdVideoPlayback );
       
  1119 
       
  1120     aCmd->SetTObjectValueL<TMPXVideoPlaybackCommand>( KMPXMediaVideoPlaybackCommand,
       
  1121                                                       EPbCmdInitView );
       
  1122 
       
  1123     iPlaybackUtility->CommandL( *aCmd );
       
  1124 }
       
  1125 
       
  1126 // -------------------------------------------------------------------------------------------------
       
  1127 //   CMPXVideoViewWrapper::ActivateClosePlayerActiveObject
       
  1128 // -------------------------------------------------------------------------------------------------
       
  1129 //
       
  1130 void CMPXVideoViewWrapper::ActivateClosePlayerActiveObject()
       
  1131 {
       
  1132     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::ActivateClosePlayerActiveObject()"));
       
  1133 
       
  1134     if ( ! iCloseAO->IsActive() )
       
  1135     {
       
  1136         iCloseAO->Start( TCallBack( CMPXVideoViewWrapper::ClosePlayerL, this ) );
       
  1137     }
       
  1138 }
       
  1139 
       
  1140 // -------------------------------------------------------------------------------------------------
       
  1141 //   CMPXVideoViewWrapper::ClosePlayerL
       
  1142 // -------------------------------------------------------------------------------------------------
       
  1143 //
       
  1144 TInt CMPXVideoViewWrapper::ClosePlayerL( TAny* aPtr )
       
  1145 {
       
  1146     MPX_DEBUG(_L("CMPXVideoViewWrapper::ClosePlayerL()"));
       
  1147 
       
  1148     static_cast<CMPXVideoViewWrapper*>(aPtr)->DoClosePlayerL();
       
  1149     return KErrNone;
       
  1150 }
       
  1151 
       
  1152 // -------------------------------------------------------------------------------------------------
       
  1153 //   CMPXVideoViewWrapper::DoClosePlayerL
       
  1154 // -------------------------------------------------------------------------------------------------
       
  1155 //
       
  1156 void CMPXVideoViewWrapper::DoClosePlayerL()
       
  1157 {
       
  1158     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::DoClosePlayerL()"));
       
  1159 
       
  1160     iView->doClosePlayer();
       
  1161 }
       
  1162 
       
  1163 // -------------------------------------------------------------------------------------------------
       
  1164 //   CMPXVideoViewWrapper::IssuePlayCommandL
       
  1165 // -------------------------------------------------------------------------------------------------
       
  1166 //
       
  1167 void CMPXVideoViewWrapper::IssuePlayCommandL()
       
  1168 {
       
  1169     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::IssuePlayCommandL()"));
       
  1170     CreateGeneralPlaybackCommandL( EPbCmdPlay );
       
  1171 }
       
  1172 
       
  1173 // -------------------------------------------------------------------------------------------------
       
  1174 //   CMPXVideoViewWrapper::RetrievePdlInformationL
       
  1175 // -------------------------------------------------------------------------------------------------
       
  1176 //
       
  1177 void CMPXVideoViewWrapper::RetrievePdlInformationL()
       
  1178 {
       
  1179     MPX_DEBUG(_L("CMPXVideoViewWrapper::RetrievePdlInformationL()"));
       
  1180 }
       
  1181 
       
  1182 // -------------------------------------------------------------------------------------------------
       
  1183 // CMPXVideoViewWrapper::CreateVideoSpecificCmdL()
       
  1184 // -------------------------------------------------------------------------------------------------
       
  1185 //
       
  1186 void CMPXVideoViewWrapper::CreateVideoSpecificCmdL( TMPXVideoPlaybackCommand aCmd )
       
  1187 {
       
  1188     //
       
  1189     //  create command to pass to playback plugin
       
  1190     //
       
  1191     CMPXCommand* cmd = CMPXCommand::NewL();
       
  1192     CleanupStack::PushL( cmd );
       
  1193 
       
  1194     cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  1195 
       
  1196     cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXMediaIdVideoPlayback );
       
  1197 
       
  1198     cmd->SetTObjectValueL<TMPXVideoPlaybackCommand>( KMPXMediaVideoPlaybackCommand, aCmd );
       
  1199 
       
  1200     iPlaybackUtility->CommandL( *cmd );
       
  1201 
       
  1202     CleanupStack::PopAndDestroy( cmd );
       
  1203 }
       
  1204 
       
  1205 // -------------------------------------------------------------------------------------------------
       
  1206 // CMPXVideoViewWrapper::SetAspectRatioL()
       
  1207 // -------------------------------------------------------------------------------------------------
       
  1208 //
       
  1209 void CMPXVideoViewWrapper::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd )
       
  1210 {
       
  1211     MPX_DEBUG(_L("CMPXVideoViewWrapper::SetAspectRatioL()"));
       
  1212 
       
  1213     TInt newAspectRatio = iDisplayHandler->SetAspectRatioL( aCmd );
       
  1214 
       
  1215     if ( iControlsController )
       
  1216     {
       
  1217         iControlsController->handleEvent( EMPXControlCmdSetAspectRatio, newAspectRatio );
       
  1218     }
       
  1219 }
       
  1220 
       
  1221 // -------------------------------------------------------------------------------------------------
       
  1222 // CMPXVideoViewWrapper::IsAppInFrontL()
       
  1223 // Returns true if app is foreground. Uses windowgroup id
       
  1224 // -------------------------------------------------------------------------------------------------
       
  1225 //
       
  1226 TBool CMPXVideoViewWrapper::IsAppInFrontL()
       
  1227 {
       
  1228     TBool ret = EFalse;
       
  1229     RWsSession wsSession;
       
  1230 
       
  1231     User::LeaveIfError( wsSession.Connect() );
       
  1232 
       
  1233     if( wsSession.Handle() )
       
  1234     {
       
  1235         CArrayFixFlat<TInt>* wgList =
       
  1236             new (ELeave) CArrayFixFlat<TInt>( wsSession.NumWindowGroups() );
       
  1237 
       
  1238         // check if our window is front or not
       
  1239         if ( wsSession.WindowGroupList( 0, wgList ) == KErrNone )
       
  1240         {
       
  1241             ret = ( CEikonEnv::Static()->RootWin().Identifier() == wgList->At(0) );			        
       
  1242         }
       
  1243         else
       
  1244         {
       
  1245             ret = EFalse;
       
  1246         }
       
  1247 
       
  1248         delete wgList;
       
  1249     }
       
  1250 
       
  1251     wsSession.Close();
       
  1252 
       
  1253     MPX_DEBUG(_L("CMPXVideoViewWrapper::IsAppInFrontL (%d)" ), ret);
       
  1254 
       
  1255     return ret;
       
  1256 }
       
  1257 
       
  1258 // -------------------------------------------------------------------------------------------------
       
  1259 //   CMPXVideoViewWrapper::ClosePlaybackViewL()
       
  1260 // -------------------------------------------------------------------------------------------------
       
  1261 //
       
  1262 void CMPXVideoViewWrapper::ClosePlaybackViewL()
       
  1263 {
       
  1264     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::closePlaybackView()"));
       
  1265         
       
  1266     iView->closePlaybackView();
       
  1267 }
       
  1268 
       
  1269 // -------------------------------------------------------------------------------------------------
       
  1270 //   CMPXVideoViewWrapper::HandleVolumeCmdL()
       
  1271 // -------------------------------------------------------------------------------------------------
       
  1272 //
       
  1273 void CMPXVideoViewWrapper::HandleVolumeCmdL( TMPXPlaybackCommand aCmd )
       
  1274 {
       
  1275     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::HandleVolumeCmdL()"));
       
  1276 
       
  1277     //
       
  1278     // In case user try to change the volume via media key, rocker key or etc
       
  1279     // We need to show the controls though the volume level doesn't get changed
       
  1280     // For examples : - try to change the volume with a clip without audio track
       
  1281     //                - try to reduce the volume with volume level 0
       
  1282     //                - try to increase the volume with max volume level
       
  1283     //
       
  1284     iControlsController->handleEvent( EMPXControlCmdShowVolumeControls );
       
  1285 
       
  1286     iPlaybackUtility->CommandL( aCmd );
       
  1287 }
       
  1288 
       
  1289 // -------------------------------------------------------------------------------------------------
       
  1290 //   CMPXVideoViewWrapper::HandleShortPressBackwardL()
       
  1291 // -------------------------------------------------------------------------------------------------
       
  1292 //
       
  1293 void CMPXVideoViewWrapper::HandleShortPressBackwardL()
       
  1294 {
       
  1295     MPX_DEBUG(_L("CMPXVideoViewWrapper::HandleCommandL()"));
       
  1296 
       
  1297     if( !iPlaylistView )
       
  1298     {
       
  1299         SetPropertyL( EPbPropertyPosition, 0 );
       
  1300     }
       
  1301 }
       
  1302 
       
  1303 // -------------------------------------------------------------------------------------------------
       
  1304 //   CMPXVideoViewWrapper::IssueVideoAppForegroundCmd()
       
  1305 // -------------------------------------------------------------------------------------------------
       
  1306 //
       
  1307 void CMPXVideoViewWrapper::IssueVideoAppForegroundCmdL( TBool aForeground )
       
  1308 {
       
  1309     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::HandleForegroundEventL()"),
       
  1310                    _L("aForeground = %d"), aForeground );
       
  1311 
       
  1312     TMPXVideoPlaybackCommand videoCmd = EPbCmdHandleBackground;
       
  1313 
       
  1314     if ( aForeground )
       
  1315     {
       
  1316         videoCmd = EPbCmdHandleForeground;
       
  1317     }
       
  1318 
       
  1319     //
       
  1320     //  create command to pass to playback plugin
       
  1321     //
       
  1322     CMPXCommand* cmd = CMPXCommand::NewL();
       
  1323     CleanupStack::PushL( cmd );
       
  1324 
       
  1325     cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  1326     cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXMediaIdVideoPlayback );
       
  1327     cmd->SetTObjectValueL<TMPXVideoPlaybackCommand>( KMPXMediaVideoPlaybackCommand, videoCmd );
       
  1328     cmd->SetTObjectValueL<TBool>( KMPXMediaVideoAppForeground, IsAppInFrontL() );
       
  1329 
       
  1330     iPlaybackUtility->CommandL( *cmd );
       
  1331     CleanupStack::PopAndDestroy( cmd );
       
  1332 }
       
  1333 
       
  1334 // -------------------------------------------------------------------------------------------------
       
  1335 //   CMPXVideoViewWrapper::CreateControlsL()
       
  1336 // -------------------------------------------------------------------------------------------------
       
  1337 //
       
  1338 void CMPXVideoViewWrapper::CreateControlsL()
       
  1339 {
       
  1340     MPX_ENTER_EXIT(_L("CMPXVideoViewWrapper::CreateControlsL()"));
       
  1341 
       
  1342     //
       
  1343     //  Query playback plugin for filename and mode
       
  1344     //
       
  1345     CMPXCommand* cmd = CMPXCommand::NewL();
       
  1346     CleanupStack::PushL( cmd );
       
  1347 
       
  1348     RetrieveFileNameAndModeL( cmd );
       
  1349 
       
  1350     //
       
  1351     //  Create a temporary file details that is populated with the
       
  1352     //  file name and playback mode.  This will be delete when
       
  1353     //  plugin initialization is complete
       
  1354     //
       
  1355     if ( iFileDetails )
       
  1356     {
       
  1357         delete iFileDetails;
       
  1358         iFileDetails = NULL;
       
  1359     }
       
  1360 
       
  1361     iFileDetails = new QMPXVideoPlaybackViewFileDetails();
       
  1362 
       
  1363     TPtrC fileName( cmd->ValueText( KMPXMediaVideoPlaybackFileName ) );    
       
  1364     const QString qFilename( (QChar*)fileName.Ptr(), fileName.Length() );
       
  1365     iFileDetails->mClipName = qFilename;
       
  1366 
       
  1367     iFileDetails->mPlaybackMode = (TMPXVideoMode) cmd->ValueTObjectL<TInt>( KMPXMediaVideoMode );
       
  1368 
       
  1369     iFileDetails->mTvOutConnected   = cmd->ValueTObjectL<TInt>( KMPXMediaVideoTvOutConnected );
       
  1370     iFileDetails->mTvOutPlayAllowed = cmd->ValueTObjectL<TInt>( KMPXMediaVideoTvOutPlayAllowed );
       
  1371 
       
  1372     TPtrC mimeType( cmd->ValueText( KMPXMediaVideoRecognizedMimeType ) );    
       
  1373     const QString qMimeType( (QChar*)mimeType.Ptr(), mimeType.Length() );
       
  1374     iFileDetails->mMimeType = qMimeType;
       
  1375 
       
  1376     //
       
  1377     // get playlist information and set mMultiItemPlaylist flag
       
  1378     //
       
  1379     TInt numItems = 1;    
       
  1380     MMPXSource* s = iPlaybackUtility->Source();
       
  1381 
       
  1382     if ( s )
       
  1383     {
       
  1384         CMPXCollectionPlaylist* playlist = NULL;
       
  1385 
       
  1386         MPX_TRAPD( err, playlist = s->PlaylistL() );
       
  1387         
       
  1388         if ( err == KErrNone && playlist )
       
  1389         {
       
  1390             iPlaylistView = ETrue;
       
  1391             numItems = playlist->Count();
       
  1392             delete playlist;
       
  1393         }
       
  1394     }
       
  1395 
       
  1396     iFileDetails->mMultiItemPlaylist = ( numItems > 1 );
       
  1397     
       
  1398     CleanupStack::PopAndDestroy( cmd );
       
  1399 
       
  1400     if ( iControlsController )
       
  1401     {
       
  1402         delete iControlsController;
       
  1403         iControlsController = NULL;
       
  1404     }
       
  1405 
       
  1406     iControlsController = new QMPXVideoPlaybackControlsController( iView, this, iFileDetails );
       
  1407 }
       
  1408 
       
  1409 // -------------------------------------------------------------------------------------------------
       
  1410 //   CMPXVideoViewWrapper::IsMultiItemPlaylist()
       
  1411 // -------------------------------------------------------------------------------------------------
       
  1412 //
       
  1413 TBool CMPXVideoViewWrapper::IsMultiItemPlaylist()
       
  1414 {
       
  1415     
       
  1416     bool multiLinks( false );
       
  1417     
       
  1418     if ( iFileDetails )
       
  1419     {
       
  1420         MPX_DEBUG(_L("CMPXVideoViewWrapper::IsMultiItemPlaylist(%d)"), 
       
  1421             iFileDetails->mMultiItemPlaylist );
       
  1422         multiLinks = iFileDetails->mMultiItemPlaylist;
       
  1423     }
       
  1424     
       
  1425     return multiLinks;
       
  1426 }
       
  1427 
       
  1428 // -------------------------------------------------------------------------------------------------
       
  1429 //   CMPXVideoViewWrapper::UpdateVideoRect()
       
  1430 // -------------------------------------------------------------------------------------------------
       
  1431 //
       
  1432 void CMPXVideoViewWrapper::UpdateVideoRect( 
       
  1433         TInt aX, TInt aY, TInt aWidth, TInt aHeight, TBool transitionEffect )
       
  1434 {
       
  1435     MPX_DEBUG(_L("CMPXVideoViewWrapper::UpdateVideoRect()"));
       
  1436 
       
  1437     TRect rect( TPoint( aX, aY ), TSize( aWidth, aHeight ) );
       
  1438     TRAP_IGNORE( iDisplayHandler->UpdateVideoRectL( rect, transitionEffect ) );
       
  1439 }
       
  1440 
       
  1441 // -------------------------------------------------------------------------------------------------
       
  1442 //   CMPXVideoViewWrapper::UpdateVideoRectDone()
       
  1443 // -------------------------------------------------------------------------------------------------
       
  1444 //
       
  1445 void CMPXVideoViewWrapper::UpdateVideoRectDone()
       
  1446 {
       
  1447     MPX_DEBUG(_L("CMPXVideoViewWrapper::UpdateVideoRectDone()"));
       
  1448 
       
  1449     iControlsController->updateVideoRectDone();
       
  1450 }
       
  1451 
       
  1452 // EOF