photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandlervideoplayback.cpp
branchRCL_3
changeset 18 78ad99c24f08
parent 13 bcb43dc84c44
child 19 420f6808bf21
equal deleted inserted replaced
17:a60acebbbd9d 18:78ad99c24f08
    45 #include <glxscreenfurniture.h>
    45 #include <glxscreenfurniture.h>
    46   
    46   
    47 #include <mpxmessage2.h> 
    47 #include <mpxmessage2.h> 
    48 #include <mpxplaybackmessage.h> 
    48 #include <mpxplaybackmessage.h> 
    49 #include <mpxmessagegeneraldefs.h> 
    49 #include <mpxmessagegeneraldefs.h> 
    50 
    50 #include <glxgallery.hrh>
    51 /**
    51 /**
    52  * @internal reviewed 11/06/2007 by Alex Birkett
    52  * @internal reviewed 11/06/2007 by Alex Birkett
    53  */
    53  */
    54 
    54 
    55 const TUid KVideoHelixPlaybackPluginUid = { 0x10282551 };
    55 const TUid KVideoHelixPlaybackPluginUid = { 0x10282551 };
       
    56 
       
    57 /**
       
    58  * Periodic interval for late construction.
       
    59  * GridView construction would take about 2 sec,
       
    60  * hence this can happen only after 2 secs 
       
    61  */
       
    62 const TTimeIntervalMicroSeconds32 KPeriodicInterval  = 2000000; // 2 sec
    56 
    63 
    57 #include "glxcommandfactory.h"
    64 #include "glxcommandfactory.h"
    58 
    65 
    59 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    60 // Two-phased constructor.
    67 // Two-phased constructor.
    88 // ---------------------------------------------------------------------------
    95 // ---------------------------------------------------------------------------
    89 //
    96 //
    90 void CGlxCommandHandlerVideoPlayback::ConstructL()
    97 void CGlxCommandHandlerVideoPlayback::ConstructL()
    91     {
    98     {
    92     iUiUtility = CGlxUiUtility::UtilityL();
    99     iUiUtility = CGlxUiUtility::UtilityL();
    93     
       
    94      
   100      
    95     iViewUtility = MMPXViewUtility::UtilityL(); 
   101     iViewUtility = MMPXViewUtility::UtilityL(); 
    96 
   102 
       
   103     //Start construct timer for late initialization of "MMPXPlaybackUtility"
       
   104     TCallBack callback(
       
   105             CGlxCommandHandlerVideoPlayback::LateConstructCallback, this);
       
   106     iPbUtilityConstructTimer = CPeriodic::NewL(CActive::EPriorityIdle);
       
   107     iPbUtilityConstructTimer->Start(KPeriodicInterval, 0, callback);
       
   108     
    97    	// Add supported commands
   109    	// Add supported commands
    98    	
       
    99    	// Play videoplayback
   110    	// Play videoplayback
   100    	TCommandInfo info(EGlxCmdPlay);
   111    	TCommandInfo info(EGlxCmdPlay);
   101 	// filter out everything except videos
   112 	// filter out everything except videos
   102 	info.iCategoryFilter = EMPXVideo;
   113 	info.iCategoryFilter = EMPXVideo;
   103 	info.iCategoryRule = TCommandInfo::ERequireAll;
   114 	info.iCategoryRule = TCommandInfo::ERequireAll;
   120     if ( iViewUtility ) 
   131     if ( iViewUtility ) 
   121         { 
   132         { 
   122         iViewUtility->Close(); 
   133         iViewUtility->Close(); 
   123         } 
   134         } 
   124 
   135 
       
   136     if (iPbUtilityConstructTimer)
       
   137         {
       
   138         iPbUtilityConstructTimer->Cancel();
       
   139         delete iPbUtilityConstructTimer;
       
   140         }
       
   141     
   125     if ( iPlaybackUtility ) 
   142     if ( iPlaybackUtility ) 
   126         { 
   143         { 
   127         TRAP_IGNORE( iPlaybackUtility->CommandL( EPbCmdClose ) ); 
   144         TRAP_IGNORE( iPlaybackUtility->CommandL( EPbCmdClose ) ); 
   128         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) ); 
   145         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) ); 
   129         iPlaybackUtility->Close(); 
   146         iPlaybackUtility->Close(); 
   186     TRACER("CGlxCommandHandlerVideoPlayback::ActivateViewL()");
   203     TRACER("CGlxCommandHandlerVideoPlayback::ActivateViewL()");
   187     
   204     
   188 	// get the focused item from the media list
   205 	// get the focused item from the media list
   189 	MGlxMediaList& mediaList = MediaList();
   206 	MGlxMediaList& mediaList = MediaList();
   190 
   207 
   191     CGlxDefaultAttributeContext* attributeContext = CGlxDefaultAttributeContext::NewL();
   208     CGlxDefaultAttributeContext* attributeContext =
       
   209             CGlxDefaultAttributeContext::NewL();
   192     CleanupStack::PushL(attributeContext);
   210     CleanupStack::PushL(attributeContext);
   193     attributeContext->AddAttributeL(KMPXMediaGeneralUri);
   211 
   194     attributeContext->AddAttributeL(KMPXMediaGeneralTitle);
   212     TInt focusIndex = mediaList.FocusIndex();
   195     attributeContext->AddAttributeL(KMPXMediaGeneralCategory);
   213     const TGlxMedia& mediaItem = mediaList.Item(focusIndex);
   196     mediaList.AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
   214     //If Item's uri is not present, only then retrieve 'uri'
   197     
   215     if (!mediaItem.Uri().Length())
   198     // TGlxContextRemover will remove the context when it goes out of scope
   216         {
   199     // Used here to avoid a trap and still have safe cleanup   
   217         //Blocking call to retrieve Item Uri
   200     TGlxFetchContextRemover contextRemover (attributeContext, mediaList);    
   218         attributeContext->AddAttributeL(KMPXMediaGeneralUri);
   201 	CleanupClosePushL( contextRemover );
   219         mediaList.AddContextL(attributeContext,
   202 	User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, mediaList));
   220                 KGlxFetchContextPriorityBlocking);
   203 	// context off the list
   221 
   204     CleanupStack::PopAndDestroy( &contextRemover );	
   222         // TGlxContextRemover will remove the context when it goes out of scope
   205 	
   223         // Used here to avoid a trap and still have safe cleanup   
   206 	TInt index = mediaList.FocusIndex();
   224         TGlxFetchContextRemover contextRemover(attributeContext, mediaList);
   207 	TGlxMedia  item = mediaList.Item(index);
   225         CleanupClosePushL(contextRemover);
   208 	const CGlxMedia* media = item.Properties();
   226 
   209 	if(media)
   227         User::LeaveIfError(GlxAttributeRetriever::RetrieveL(
   210 		{
   228                 *attributeContext, mediaList));
   211         if(media->IsSupported(KMPXMediaGeneralUri))
   229         // context off the list
   212             {
   230         CleanupStack::PopAndDestroy(&contextRemover);
   213             if (!iPlaybackUtility)
   231         }
   214                 {
   232 
   215                 GLX_LOG_INFO( "CmdHandler VideoPlayback - SelectPlayerL(+)" );
   233     //Check if 'MPXPlaybackUtility' is already constructed
   216                 const TUid playbackMode = { 0x200009EE };  // photos UID
   234     if (!iPlaybackUtility)
   217                 iPlaybackUtility = MMPXPlaybackUtility::UtilityL(EMPXCategoryVideo, playbackMode );
   235         {
   218                 MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
   236         PlaybackUtilityL();
   219                 manager.SelectPlayerL( KVideoHelixPlaybackPluginUid );
   237         }
   220                 iPlaybackUtility->AddObserverL( *this ); 
   238     // MPX playbackutility instead of VIA Player 	
   221                 GLX_LOG_INFO( "CmdHandler VideoPlayback - SelectPlayerL(-)" );
   239     // Causes callback to HandlePlaybackMessage() 
   222                 }
   240     iPlaybackUtility->InitL(mediaItem.Uri());
   223             // MPX playbackutility instead of VIA Player 
   241 
   224             const TDesC& filename = media->ValueText(KMPXMediaGeneralUri); 
       
   225             // Causes callback to HandlePlaybackMessage() 
       
   226             iPlaybackUtility->InitL(filename); 
       
   227             }
       
   228         }
       
   229     CleanupStack::PopAndDestroy(attributeContext);
   242     CleanupStack::PopAndDestroy(attributeContext);
   230     }
   243     }
       
   244 
   231 // -----------------------------------------------------------------------------
   245 // -----------------------------------------------------------------------------
   232 // DoActivateL - Activate this command handler
   246 // DoActivateL - Activate this command handler
   233 // -----------------------------------------------------------------------------
   247 // -----------------------------------------------------------------------------
   234 //
   248 //
   235 void CGlxCommandHandlerVideoPlayback::DoActivateL(TInt aViewId)
   249 void CGlxCommandHandlerVideoPlayback::DoActivateL(TInt aViewId)
   460     // Causes view switch to playback view 
   474     // Causes view switch to playback view 
   461     iViewUtility->ActivateViewL( array ); 
   475     iViewUtility->ActivateViewL( array ); 
   462     CleanupStack::PopAndDestroy( &array ); 
   476     CleanupStack::PopAndDestroy( &array ); 
   463     } 
   477     } 
   464 
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CGlxCommandHandlerVideoPlayback::LateConstructCallback
       
   481 // -----------------------------------------------------------------------------
       
   482 TInt CGlxCommandHandlerVideoPlayback::LateConstructCallback(TAny* aPtr)
       
   483     {
       
   484     TRACER("CGlxCommandHandlerVideoPlayback::LateConstructCallback");
       
   485     static_cast<CGlxCommandHandlerVideoPlayback*>(aPtr)->DoLateConstruct();
       
   486     return KErrNone;
       
   487     }
       
   488 
       
   489 // -----------------------------------------------------------------------------
       
   490 // CGlxCommandHandlerVideoPlayback::DoLateConstruct
       
   491 // -----------------------------------------------------------------------------
       
   492 void CGlxCommandHandlerVideoPlayback::DoLateConstruct()
       
   493     {
       
   494     TRACER("CGlxCommandHandlerVideoPlayback::DoLateConstruct");
       
   495     //Cancel the periodic timer
       
   496     iPbUtilityConstructTimer->Cancel();
       
   497     //Start 'MMPXPlaybackUtility' construction
       
   498     TRAP_IGNORE( PlaybackUtilityL());
       
   499     }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CGlxCommandHandlerVideoPlayback::PlaybackUtilityL
       
   503 // -----------------------------------------------------------------------------
       
   504 void CGlxCommandHandlerVideoPlayback::PlaybackUtilityL()
       
   505     {
       
   506     TRACER("CGlxCommandHandlerVideoPlayback::PlaybackUtilityL");
       
   507     if (!iPlaybackUtility)
       
   508         {
       
   509         iPlaybackUtility = MMPXPlaybackUtility::UtilityL(EMPXCategoryVideo,
       
   510 				TUid::Uid(KGlxGalleryApplicationUid) ); //use photos UID
       
   511         MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
   512         manager.SelectPlayerL(KVideoHelixPlaybackPluginUid);
       
   513         iPlaybackUtility->AddObserverL(*this);
       
   514         }
       
   515     }