|
1 /* |
|
2 * Copyright (c) 2008-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: Video Playback command handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxcommandhandlervideoplayback.h" |
|
22 |
|
23 #include <AknUtils.h> |
|
24 #include <bautils.h> |
|
25 #include <data_caging_path_literals.hrh> |
|
26 #include <mpxcollectionpath.h> |
|
27 #include <StringLoader.h> |
|
28 #include <glxviewpluginuids.hrh> |
|
29 |
|
30 #include <glxuiutilities.rsg> |
|
31 #include <mglxmedialist.h> |
|
32 #include <glxuistd.h> |
|
33 #include <glxcommandhandlers.hrh> |
|
34 #include <mpxviewutility.h> |
|
35 #include <mglxmedialistprovider.h> |
|
36 #include <glxattributeretriever.h> |
|
37 #include <glxattributecontext.h> |
|
38 //#include <ipvideo/ViaPlayerDefaultView.h> |
|
39 #include <glxtracer.h> |
|
40 #include <glxlog.h> |
|
41 #include <alf/alfdisplay.h> |
|
42 #include <glxuiutility.h> |
|
43 #include <glxicons.mbg> |
|
44 #include <glxfetchcontextremover.h> |
|
45 #include <glxscreenfurniture.h> |
|
46 |
|
47 #include <mpxmessage2.h> |
|
48 #include <mpxplaybackmessage.h> |
|
49 #include <mpxmessagegeneraldefs.h> |
|
50 |
|
51 /** |
|
52 * @internal reviewed 11/06/2007 by Alex Birkett |
|
53 */ |
|
54 |
|
55 const TUid KVideoHelixPlaybackPluginUid = { 0x10282551 }; |
|
56 |
|
57 #include "glxcommandfactory.h" |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Two-phased constructor. |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CGlxCommandHandlerVideoPlayback* CGlxCommandHandlerVideoPlayback::NewL( |
|
64 MGlxMediaListProvider* aMediaListProvider) |
|
65 { |
|
66 CGlxCommandHandlerVideoPlayback* self = new ( ELeave ) |
|
67 CGlxCommandHandlerVideoPlayback(aMediaListProvider); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // C++ default constructor can NOT contain any code, that |
|
76 // might leave. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CGlxCommandHandlerVideoPlayback::CGlxCommandHandlerVideoPlayback(MGlxMediaListProvider* |
|
80 aMediaListProvider) |
|
81 : CGlxMediaListCommandHandler(aMediaListProvider), iIconDisplayState(EUndefined) |
|
82 { |
|
83 // Do nothing |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Symbian 2nd phase constructor can leave. |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CGlxCommandHandlerVideoPlayback::ConstructL() |
|
91 { |
|
92 iUiUtility = CGlxUiUtility::UtilityL(); |
|
93 |
|
94 const TUid playbackMode = { 0x200009EE }; // photos UID |
|
95 iPlaybackUtility = MMPXPlaybackUtility::UtilityL( playbackMode ); |
|
96 MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager(); |
|
97 manager.SelectPlayerL( KVideoHelixPlaybackPluginUid ); |
|
98 iPlaybackUtility->AddObserverL( *this ); |
|
99 |
|
100 iViewUtility = MMPXViewUtility::UtilityL(); |
|
101 |
|
102 // Add supported commands |
|
103 |
|
104 // Play videoplayback |
|
105 TCommandInfo info(EGlxCmdPlay); |
|
106 // filter out everything except videos |
|
107 info.iCategoryFilter = EMPXVideo; |
|
108 info.iCategoryRule = TCommandInfo::ERequireAll; |
|
109 info.iMinSelectionLength = 1; |
|
110 info.iMaxSelectionLength = 1; |
|
111 AddCommandL(info); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Destructor |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 EXPORT_C CGlxCommandHandlerVideoPlayback::~CGlxCommandHandlerVideoPlayback() |
|
119 { |
|
120 if (iUiUtility) |
|
121 { |
|
122 iUiUtility->Close(); |
|
123 } |
|
124 |
|
125 if ( iViewUtility ) |
|
126 { |
|
127 iViewUtility->Close(); |
|
128 } |
|
129 |
|
130 if ( iPlaybackUtility ) |
|
131 { |
|
132 TRAP_IGNORE( iPlaybackUtility->CommandL( EPbCmdClose ) ); |
|
133 TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) ); |
|
134 iPlaybackUtility->Close(); |
|
135 } |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // DoExecute - the relevant action for the command id |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 TBool CGlxCommandHandlerVideoPlayback::DoExecuteL(TInt aCommandId, |
|
143 MGlxMediaList& /*aList*/) |
|
144 { |
|
145 TRACER("CGlxCommandHandlerVideoPlayback::DoExecuteL()"); |
|
146 TBool handledCommand = ETrue; |
|
147 |
|
148 switch (aCommandId) |
|
149 { |
|
150 case EGlxCmdPlay: |
|
151 { |
|
152 //Setting the navigational Status to Forwards when Play is activated |
|
153 //and is set backwards in ActivatePreviousViewL |
|
154 iUiUtility->SetViewNavigationDirection( EGlxNavigationForwards ); |
|
155 // Activate the videoplayback view |
|
156 ActivateViewL(); |
|
157 break; |
|
158 } |
|
159 default: |
|
160 { |
|
161 handledCommand = EFalse; |
|
162 break; |
|
163 } |
|
164 } |
|
165 return handledCommand; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // DoDynInitMenuPaneL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CGlxCommandHandlerVideoPlayback::DoDynInitMenuPaneL(TInt /*aResourceId*/, |
|
173 CEikMenuPane* aMenuPane) |
|
174 { |
|
175 TInt pos = 0; |
|
176 |
|
177 // If the menu contains Play command and if the device supports touch interface, |
|
178 // hide the Play command in the menu. (Since the user can Play by just tapping on the video |
|
179 // thumbnail in case of grid view and play icon in case of fullscreen view) |
|
180 if(iUiUtility->IsPenSupported() && aMenuPane->MenuItemExists(EGlxCmdPlay,pos)) |
|
181 { |
|
182 aMenuPane->SetItemDimmed( EGlxCmdPlay, ETrue); |
|
183 } |
|
184 } |
|
185 // ----------------------------------------------------------------------------- |
|
186 // ActivateViewL - launch the ViaPlayer view |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CGlxCommandHandlerVideoPlayback::ActivateViewL() |
|
190 { |
|
191 TRACER("CGlxCommandHandlerVideoPlayback::ActivateViewL()"); |
|
192 |
|
193 // get the focused item from the media list |
|
194 MGlxMediaList& mediaList = MediaList(); |
|
195 |
|
196 CGlxDefaultAttributeContext* attributeContext = CGlxDefaultAttributeContext::NewL(); |
|
197 CleanupStack::PushL(attributeContext); |
|
198 attributeContext->AddAttributeL(KMPXMediaGeneralUri); |
|
199 attributeContext->AddAttributeL(KMPXMediaGeneralTitle); |
|
200 attributeContext->AddAttributeL(KMPXMediaGeneralCategory); |
|
201 mediaList.AddContextL(attributeContext, KGlxFetchContextPriorityBlocking); |
|
202 |
|
203 // TGlxContextRemover will remove the context when it goes out of scope |
|
204 // Used here to avoid a trap and still have safe cleanup |
|
205 TGlxFetchContextRemover contextRemover (attributeContext, mediaList); |
|
206 CleanupClosePushL( contextRemover ); |
|
207 User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, mediaList)); |
|
208 // context off the list |
|
209 CleanupStack::PopAndDestroy( &contextRemover ); |
|
210 |
|
211 TInt index = mediaList.FocusIndex(); |
|
212 TGlxMedia item = mediaList.Item(index); |
|
213 const CGlxMedia* media = item.Properties(); |
|
214 if(media) |
|
215 { |
|
216 if(media->IsSupported(KMPXMediaGeneralUri)) |
|
217 { |
|
218 // MPX playbackutility instead of VIA Player |
|
219 const TDesC& filename = media->ValueText(KMPXMediaGeneralUri); |
|
220 // Causes callback to HandlePlaybackMessage() |
|
221 iPlaybackUtility->InitL(filename); |
|
222 } |
|
223 } |
|
224 CleanupStack::PopAndDestroy(attributeContext); |
|
225 } |
|
226 // ----------------------------------------------------------------------------- |
|
227 // DoActivateL - Activate this command handler |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CGlxCommandHandlerVideoPlayback::DoActivateL(TInt aViewId) |
|
231 { |
|
232 TRACER("CGlxCommandHandlerVideoPlayback::DoActivateL()"); |
|
233 iViewId = aViewId; |
|
234 |
|
235 MGlxMediaList& mediaList = MediaList(); |
|
236 |
|
237 mediaList.AddMediaListObserverL(this); |
|
238 |
|
239 iIconDisplayState = EVisible; |
|
240 |
|
241 iAttributeContext = CGlxDefaultAttributeContext::NewL(); |
|
242 iAttributeContext->SetRangeOffsets(1, 1); |
|
243 iAttributeContext->AddAttributeL(KMPXMediaGeneralCategory); |
|
244 mediaList.AddContextL( iAttributeContext, KGlxFetchContextPriorityLow ); |
|
245 |
|
246 SetToolBar(); |
|
247 } |
|
248 // ----------------------------------------------------------------------------- |
|
249 // Deactivate - Deactivate this command handler |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CGlxCommandHandlerVideoPlayback::Deactivate() |
|
253 { |
|
254 TRACER("CGlxCommandHandlerVideoPlayback::Deactivate()"); |
|
255 |
|
256 MGlxMediaList& mediaList = MediaList(); |
|
257 |
|
258 if (iAttributeContext) |
|
259 { |
|
260 mediaList.RemoveContext(iAttributeContext); |
|
261 delete iAttributeContext; |
|
262 iAttributeContext = NULL; |
|
263 } |
|
264 |
|
265 mediaList.RemoveMediaListObserver(this); |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // HandleAttributesAvailableL - Sets the toolbar according to the attributes |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CGlxCommandHandlerVideoPlayback::HandleAttributesAvailableL(TInt aItemIndex, const RArray<TMPXAttribute>& aAttributes, MGlxMediaList* /* aList */) |
|
273 { |
|
274 TRACER("CGlxCommandHandlerVideoPlayback::HandleAttributesAvailableL()"); |
|
275 if (MediaList().FocusIndex() == aItemIndex ) |
|
276 { |
|
277 TIdentityRelation<TMPXAttribute> match(TMPXAttribute::Match); |
|
278 if (KErrNotFound != aAttributes.Find(KMPXMediaGeneralCategory, match)) |
|
279 { |
|
280 SetToolBar(); |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // HandleFocusChangedL - Handles a Focus change in the media list |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CGlxCommandHandlerVideoPlayback::HandleFocusChangedL(NGlxListDefs::TFocusChangeType |
|
291 /* aType */, TInt /* aNewIndex */, TInt /* aOldIndex */, MGlxMediaList* /* aList */) |
|
292 { |
|
293 TRACER("CGlxCommandHandlerVideoPlayback::HandleFocusChangedL()"); |
|
294 SetToolBar(); |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // SetToolBarL - Set the toolbar to the correct state. |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CGlxCommandHandlerVideoPlayback::SetToolBar() |
|
302 { |
|
303 TRACER("CGlxCommandHandlerVideoPlayback::SetToolBar()"); |
|
304 TInt focus = MediaList().FocusIndex(); |
|
305 if ( focus >= 0 ) |
|
306 { |
|
307 // Only show the icon if video is in focus |
|
308 TMPXGeneralCategory category = MediaList().Item(focus).Category(); |
|
309 TBool visible = (EMPXVideo == category); |
|
310 |
|
311 // Decide if we need to update the toolbar |
|
312 TBool UpdateToolBar = EFalse; |
|
313 |
|
314 if (visible) |
|
315 { |
|
316 if (iIconDisplayState != EVisible) |
|
317 { |
|
318 UpdateToolBar = ETrue; |
|
319 } |
|
320 } |
|
321 else |
|
322 { |
|
323 if (iIconDisplayState != EHidden) |
|
324 { |
|
325 UpdateToolBar = ETrue; |
|
326 } |
|
327 } |
|
328 |
|
329 // Update the toolbar if need be. |
|
330 if (UpdateToolBar) |
|
331 { |
|
332 iUiUtility->ScreenFurniture()->SetToolbarItemVisibility( EGlxCmdPlay, visible ); |
|
333 iIconDisplayState = (visible ? EVisible : EHidden); |
|
334 } |
|
335 } |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // HandlePlaybackMessage |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CGlxCommandHandlerVideoPlayback::HandlePlaybackMessage( CMPXMessage* aMessage, TInt aError ) |
|
343 { |
|
344 TRACER("CGlxCommandHandlerVideoPlayback::HandlePlaybackMessage()"); |
|
345 |
|
346 if ( aError == KErrNone && aMessage ) |
|
347 { |
|
348 TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); |
|
349 } |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // DoHandlePlaybackMessageL |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 void CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL( const CMPXMessage& aMessage ) |
|
357 { |
|
358 TRACER("CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL()"); |
|
359 |
|
360 TMPXMessageId id( *aMessage.Value< TMPXMessageId >( KMPXMessageGeneralId ) ); |
|
361 |
|
362 GLX_LOG_INFO1( "CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL TMPXMessageId =0x%08x",id); |
|
363 |
|
364 if ( KMPXMessageGeneral == id ) |
|
365 { |
|
366 switch ( *aMessage.Value<TInt>( KMPXMessageGeneralEvent ) ) |
|
367 { |
|
368 case TMPXPlaybackMessage::EPlayerChanged: |
|
369 { |
|
370 // Need to call MMPXPlaybackUtility::CurrentPlayer() to get new features |
|
371 GLX_LOG_INFO( "CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL: EPlayerChanged" ); |
|
372 HandlePlaybackPlayerChangedL(); |
|
373 break; |
|
374 } |
|
375 case TMPXPlaybackMessage::EInitializeComplete: |
|
376 { |
|
377 GLX_LOG_INFO( "CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL: EInitializeComplete" ); |
|
378 break; |
|
379 } |
|
380 case TMPXPlaybackMessage::EPlayerUnavailable: |
|
381 { |
|
382 GLX_LOG_INFO( "CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL: EPlayerUnavailable" ); |
|
383 break; |
|
384 } |
|
385 case TMPXPlaybackMessage::EPropertyChanged: |
|
386 { |
|
387 GLX_LOG_INFO( "CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL: EPropertyChanged" ); |
|
388 break; |
|
389 } |
|
390 case TMPXPlaybackMessage::EError: |
|
391 { |
|
392 GLX_LOG_INFO1( "CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL error = %d", |
|
393 *aMessage.Value<TInt>( KMPXMessageGeneralData ) ); |
|
394 break; |
|
395 } |
|
396 |
|
397 case TMPXPlaybackMessage::EStateChanged: |
|
398 { |
|
399 break; |
|
400 } |
|
401 case TMPXPlaybackMessage::ECommandReceived: // iType=TMPXPlaybackCommand |
|
402 case TMPXPlaybackMessage::ECommandComplete: // iType=TMPXPlaybackCommand |
|
403 case TMPXPlaybackMessage::ESongCorrupt: |
|
404 case TMPXPlaybackMessage::ESongContainerChanged: // Need to call MMPXMedia::CollectionPathL() to get new path |
|
405 case TMPXPlaybackMessage::ESongChanged: // iData=new index; need to query to get new properties (e.g. duration: title etc.) |
|
406 case TMPXPlaybackMessage::EActivePlayerChanged: // iData=active/inactive (ETrue/EFalse); iType (ETrue:rebind to ActivePlayerMode) |
|
407 case TMPXPlaybackMessage::ESubPlayersChanged: // Need to query to get new list of sub players |
|
408 case TMPXPlaybackMessage::EPlayerSelectionChanged: // Need to query MMPXPlayerManager::GetSelectionL() |
|
409 case TMPXPlaybackMessage::EDownloadStarted: // iData=total expected bytes |
|
410 case TMPXPlaybackMessage::EDownloadUpdated: // iData=total bytes so far |
|
411 case TMPXPlaybackMessage::EDownloadComplete: // iData=total bytes downloaded |
|
412 case TMPXPlaybackMessage::EDownloadPositionChanged: // iData=total bytes so far |
|
413 case TMPXPlaybackMessage::EDownloadStateChanged: // iData=TMPXPlaybackPdDownloadState |
|
414 case TMPXPlaybackMessage::EDownloadCmdPauseDownload: // iData=transaction ID |
|
415 case TMPXPlaybackMessage::EDownloadCmdResumeDownload: // iData=transaction ID |
|
416 case TMPXPlaybackMessage::EDownloadCmdCancelDownload: // iData=transaction ID |
|
417 case TMPXPlaybackMessage::EAccessoryChanged: // iType=TAccessoryMode |
|
418 case TMPXPlaybackMessage::EMediaChanged: // When the song/playlist hasn't: but data may become available |
|
419 case TMPXPlaybackMessage::ESkipping: //skipping event, iData=+1, skipping forward, -1, skipping backward |
|
420 case TMPXPlaybackMessage::ESkipEnd: //skipping end |
|
421 case TMPXPlaybackMessage::EPlaylistUpdated: // playlist updated |
|
422 case TMPXPlaybackMessage::EReachedEndOfPlaylist: // playback or skipping forward has reached end of playlist |
|
423 { |
|
424 GLX_LOG_INFO1( "CGlxCommandHandlerVideoPlayback::DoHandlePlaybackMessageL KMPXMessageGeneralEvent = %d", |
|
425 *aMessage.Value<TInt>( KMPXMessageGeneralEvent ) ); |
|
426 break; |
|
427 } |
|
428 default: |
|
429 { |
|
430 break; |
|
431 } |
|
432 } |
|
433 } |
|
434 } |
|
435 |
|
436 // ----------------------------------------------------------------------------- |
|
437 // HandlePlaybackPlayerChangedL |
|
438 // ----------------------------------------------------------------------------- |
|
439 // |
|
440 void CGlxCommandHandlerVideoPlayback::HandlePlaybackPlayerChangedL() |
|
441 { |
|
442 TRACER("CGlxCommandHandlerVideoPlayback::HandlePlaybackPlayerChangedL()"); |
|
443 |
|
444 MMPXPlayer* player = iPlaybackUtility->PlayerManager().CurrentPlayer(); |
|
445 |
|
446 TUid pluginUid( KNullUid ); |
|
447 RArray<TUid> array; |
|
448 CleanupClosePushL( array ); |
|
449 |
|
450 if ( player ) |
|
451 { |
|
452 pluginUid = player->UidL(); |
|
453 array.AppendL( pluginUid ); |
|
454 } |
|
455 // Causes view switch to playback view |
|
456 iViewUtility->ActivateViewL( array ); |
|
457 CleanupStack::PopAndDestroy( &array ); |
|
458 } |
|
459 |