|
1 /* |
|
2 * Copyright (c) 2006 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: Handles commands passed in by other appilcations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <bldvariant.hrh> |
|
21 #include <apgtask.h> |
|
22 #include <eikenv.h> |
|
23 #include <coeutils.h> |
|
24 #include <mpxplaybackutility.h> |
|
25 #include <mpxplaybackmessage.h> |
|
26 #include <mpxviewutility.h> |
|
27 #include <mpxmusicplayerviewplugin.hrh> |
|
28 #include <mpxparameter.h> |
|
29 #include <mpxmessagegeneraldefs.h> |
|
30 #include <mpxplaybackmessagedefs.h> |
|
31 #include <mpxmediacontainerdefs.h> |
|
32 #include <mpxmediaarray.h> |
|
33 #include <AiwGenericParam.h> |
|
34 #include <pathinfo.h> |
|
35 #include <mpxcommandgeneraldefs.h> |
|
36 #include <caf/caferr.h> |
|
37 #include <StringLoader.h> |
|
38 |
|
39 #include <mpxcollectionplaylist.h> |
|
40 #include <mpxcollectionpath.h> |
|
41 #include <mpxcollectionplugin.hrh> |
|
42 #include <mpxdrmmediautility.h> |
|
43 #include <mpxmediadrmdefs.h> |
|
44 |
|
45 #include "mpxtlshelper.h" |
|
46 #include "mpxconstants.h" |
|
47 #include "mpxPDcommandhandler.h" |
|
48 #include "mpxlog.h" |
|
49 #include "mpxcommonuihelper.h" |
|
50 #include <mpxmediakeyhandler.rsg> |
|
51 |
|
52 // CONSTANTS |
|
53 #define KProgressDownloadUid 0x10207BCD |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS ============================== |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // Two-phased constructor. |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 CMPXPdCommandHandler* CMPXPdCommandHandler::NewL( |
|
62 MMPXPlaybackUtility* aPlaybackUtility) |
|
63 { |
|
64 CMPXPdCommandHandler* self = NewLC(aPlaybackUtility); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // Two-phased constructor. |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 CMPXPdCommandHandler* CMPXPdCommandHandler::NewLC( |
|
74 MMPXPlaybackUtility* aPlaybackUtility) |
|
75 { |
|
76 CMPXPdCommandHandler* self = new ( ELeave ) CMPXPdCommandHandler( aPlaybackUtility ); |
|
77 CleanupStack::PushL(self); |
|
78 self->ConstructL(); |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // C++ constructor can NOT contain any code that might leave. |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 CMPXPdCommandHandler::CMPXPdCommandHandler( |
|
87 MMPXPlaybackUtility* aPlaybackUtility ): |
|
88 iPlaybackUtility( aPlaybackUtility ) |
|
89 ,iPlaybackCompleted(EFalse) |
|
90 ,iPrevousPlaybackState(EPbStateNotInitialised) |
|
91 { |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // Destructor. |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 CMPXPdCommandHandler::~CMPXPdCommandHandler() |
|
99 { |
|
100 if ( iPdPlaybackUtility ) |
|
101 { |
|
102 TRAP_IGNORE( iPdPlaybackUtility->RemoveObserverL( *this ) ); |
|
103 TRAP_IGNORE( iPdPlaybackUtility->CommandL( EPbCmdStop ) ); |
|
104 TRAP_IGNORE( iPdPlaybackUtility->CommandL( EPbCmdClose ) ); |
|
105 iPdPlaybackUtility->PlayerManager().ClearSelectPlayersL(); |
|
106 iPdPlaybackUtility->Close(); |
|
107 } |
|
108 if ( iViewUtility ) |
|
109 { |
|
110 iViewUtility->Close(); |
|
111 } |
|
112 delete iDrmMediaUtility; |
|
113 delete iCommonUiHelper; |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // Symbian 2nd phase constructor can leave. |
|
118 // ---------------------------------------------------------------------------- |
|
119 // |
|
120 void CMPXPdCommandHandler::ConstructL() |
|
121 { |
|
122 iViewUtility = MMPXViewUtility::UtilityL(); |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // Handle playback message. |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CMPXPdCommandHandler::HandlePlaybackMessage( |
|
131 CMPXMessage* aMessage, TInt aError ) |
|
132 { |
|
133 if ( aError == KErrNone && aMessage ) |
|
134 { |
|
135 TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); |
|
136 } |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // Handle playback message |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CMPXPdCommandHandler::DoHandlePlaybackMessageL( const CMPXMessage& aMessage ) |
|
145 { |
|
146 MPX_FUNC( "CMPXPdCommandHandler::DoHandlePlaybackMessageL" ); |
|
147 TMPXMessageId id( *aMessage.Value<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
148 if ( KMPXMessageGeneral == id ) |
|
149 { |
|
150 switch ( *aMessage.Value<TInt>( KMPXMessageGeneralEvent ) ) |
|
151 { |
|
152 case TMPXPlaybackMessage::EInitializeComplete: |
|
153 break; |
|
154 |
|
155 case TMPXPlaybackMessage::EDownloadCmdCancelDownload: |
|
156 iPdPlaybackUtility->PlayerManager().ClearSelectPlayersL(); |
|
157 iPlaybackCompleted = ETrue; |
|
158 break; |
|
159 |
|
160 case TMPXPlaybackMessage::EStateChanged: |
|
161 { |
|
162 TInt type( *aMessage.Value<TInt>( KMPXMessageGeneralType ) ); |
|
163 MPX_DEBUG2( "CMPXPdSbPlaybackViewImp::DoHandlePlaybackMessageL - EStateChanged(%d)", type ); |
|
164 |
|
165 TMPXPlaybackState state = |
|
166 static_cast<TMPXPlaybackState>( type ); |
|
167 DoHandleStateChangedL( state ); |
|
168 iPrevousPlaybackState = state; |
|
169 break; |
|
170 } |
|
171 case TMPXPlaybackMessage::EMediaChanged: |
|
172 |
|
173 iPlaybackCompleted = ETrue; |
|
174 break; |
|
175 default: |
|
176 { |
|
177 // ignore other playback messages |
|
178 break; |
|
179 } |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CMPXAppUi::HandleCommandParametersL |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CMPXPdCommandHandler::HandleCommandParametersL( |
|
190 const TDesC8& aParams ) |
|
191 { |
|
192 CBufFlat* paramBuf = CBufFlat::NewL( /*anExpandSize*/1 ); |
|
193 CleanupStack::PushL( paramBuf ); |
|
194 paramBuf->InsertL( 0, aParams ); |
|
195 RBufReadStream readStream( *paramBuf ); |
|
196 |
|
197 CAiwGenericParamList* genParList = CAiwGenericParamList::NewLC( readStream ); |
|
198 |
|
199 // Unpack download ID |
|
200 TInt index = 0; |
|
201 |
|
202 const TAiwGenericParam* genParam = genParList->FindFirst( index, |
|
203 EGenericParamDownloadId, EVariantTypeTInt32 ); |
|
204 TInt32 downloadID; |
|
205 if ( genParam ) |
|
206 { |
|
207 genParam->Value().Get( downloadID ); |
|
208 } |
|
209 else |
|
210 { |
|
211 CleanupStack::PopAndDestroy( genParList ); |
|
212 CleanupStack::PopAndDestroy( paramBuf ); |
|
213 if (!iPdPlaybackUtility) |
|
214 { |
|
215 iPlaybackCompleted = ETrue; |
|
216 } |
|
217 |
|
218 return KErrNotFound; |
|
219 } |
|
220 |
|
221 index = 0; |
|
222 // Unpack fileName |
|
223 const TAiwGenericParam* paramFileName = |
|
224 genParList->FindFirst( index, EGenericParamFile, EVariantTypeDesC ); |
|
225 TPtrC fileName; |
|
226 if ( index == KErrNotFound ) |
|
227 { |
|
228 fileName.Set( KNullDesC ); |
|
229 } |
|
230 else |
|
231 { |
|
232 fileName.Set( paramFileName->Value().AsDes() ); |
|
233 } |
|
234 if (!ConeUtils::FileExists(fileName)) |
|
235 { |
|
236 CleanupStack::PopAndDestroy( genParList ); |
|
237 CleanupStack::PopAndDestroy( paramBuf ); |
|
238 if (!iPdPlaybackUtility) |
|
239 { |
|
240 iPlaybackCompleted = ETrue; |
|
241 } |
|
242 return KErrNotFound; |
|
243 } |
|
244 if ( downloadID == KErrNotFound ) |
|
245 { |
|
246 if ( iPdPlaybackUtility ) |
|
247 { |
|
248 if ( iPdPlaybackUtility->StateL() == EPbStatePlaying ) |
|
249 { |
|
250 iPdPlaybackUtility->CommandL(EPbCmdPause); |
|
251 } |
|
252 } |
|
253 iPlaybackUtility->InitL(fileName); |
|
254 MMPXPlayer* player = |
|
255 iPlaybackUtility->PlayerManager().CurrentPlayer(); |
|
256 TUid pluginUid( KNullUid ); |
|
257 RArray<TUid> array; |
|
258 CleanupClosePushL( array ); |
|
259 |
|
260 if ( player ) |
|
261 { |
|
262 array.AppendL( player->UidL() ); |
|
263 } |
|
264 else |
|
265 { |
|
266 array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid ) ); |
|
267 } |
|
268 |
|
269 // add the collection plugin UID to ensure the correct |
|
270 // last playback view is activated |
|
271 MMPXSource* source = iPlaybackUtility->Source(); |
|
272 if( source ) |
|
273 { |
|
274 CMPXCollectionPlaylist* pl = source->PlaylistL(); |
|
275 if (pl) |
|
276 { |
|
277 CleanupStack::PushL( pl ); |
|
278 const CMPXCollectionPath& path = pl->Path(); |
|
279 if(path.Levels() > 0) |
|
280 { |
|
281 array.AppendL(TUid::Uid(path.Id(0))); |
|
282 } |
|
283 CleanupStack::PopAndDestroy( pl ); |
|
284 } |
|
285 } |
|
286 iViewUtility->ActivateViewL( array ); |
|
287 CleanupStack::PopAndDestroy( &array ); |
|
288 |
|
289 } |
|
290 else if ( iCurrentFileName == fileName && iPdPlaybackUtility) |
|
291 { |
|
292 if ( iPlaybackUtility ) |
|
293 { |
|
294 if ( iPlaybackUtility->StateL() == EPbStatePlaying ) |
|
295 { |
|
296 iPlaybackUtility->CommandL(EPbCmdPause); |
|
297 } |
|
298 } |
|
299 if ( iPdPlaybackUtility->StateL() == EPbStatePaused ) |
|
300 { |
|
301 iPdPlaybackUtility->CommandL( EPbCmdPlay ); |
|
302 } |
|
303 ActivatePlaybackViewL(); |
|
304 } |
|
305 else |
|
306 { |
|
307 // Create a new playback utility instance |
|
308 if (iPdPlaybackUtility) |
|
309 { |
|
310 iPdPlaybackUtility->RemoveObserverL( *this ); |
|
311 iPdPlaybackUtility->PlayerManager().ClearSelectPlayersL(); |
|
312 iPdPlaybackUtility->Close(); |
|
313 } |
|
314 iPdPlaybackUtility = MMPXPlaybackUtility::UtilityL( |
|
315 TUid::Uid(KProgressDownloadUid) ); |
|
316 MMPXPlayerManager& manager = iPdPlaybackUtility->PlayerManager(); |
|
317 manager.SelectPlayerL(TUid::Uid(KProgressDownloadUid)); |
|
318 iPdPlaybackUtility->AddObserverL(*this); |
|
319 |
|
320 SendCustomCommandToMPXL( downloadID, EPbCmdStartPd ); |
|
321 iPlaybackCompleted = EFalse; |
|
322 if ( iPlaybackUtility && iPlaybackUtility->StateL() == EPbStatePlaying ) |
|
323 { |
|
324 iPlaybackUtility->CommandL(EPbCmdPause); |
|
325 } |
|
326 iPdPlaybackUtility->InitL(fileName); |
|
327 ActivatePlaybackViewL(); |
|
328 iCurrentFileName=fileName; |
|
329 } |
|
330 CleanupStack::PopAndDestroy( genParList ); |
|
331 CleanupStack::PopAndDestroy( paramBuf ); |
|
332 |
|
333 return KErrNone; |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // Handle media key commands. |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CMPXPdCommandHandler::HandleCommandL( |
|
341 TMPXPlaybackCommand aCommand ) |
|
342 { |
|
343 MPX_FUNC( "CMPXPdCommandHandler::HandleCommandL" ); |
|
344 MMPXPlaybackUtility* activePlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeActivePlayer ); |
|
345 if (activePlaybackUtility) |
|
346 { |
|
347 CleanupClosePushL(*activePlaybackUtility); |
|
348 activePlaybackUtility->CommandL(aCommand); |
|
349 CleanupStack::PopAndDestroy(activePlaybackUtility); |
|
350 } |
|
351 } |
|
352 |
|
353 // --------------------------------------------------------------------------- |
|
354 // Current state of player |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 TMPXPlaybackState CMPXPdCommandHandler::PdStateL() const |
|
358 { |
|
359 MPX_FUNC( "CMPXPdCommandHandler::PdStateL" ); |
|
360 TMPXPlaybackState pbPlayerState( EPbStateNotInitialised ); |
|
361 if ( iPdPlaybackUtility ) |
|
362 { |
|
363 pbPlayerState = iPdPlaybackUtility->StateL(); |
|
364 } |
|
365 |
|
366 return pbPlayerState; |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------- |
|
370 // CMPXPdCommandHandler::ActivatePlaybackViewL() |
|
371 // --------------------------------------------------------- |
|
372 // |
|
373 void CMPXPdCommandHandler::ActivatePlaybackViewL() |
|
374 { |
|
375 MMPXPlayer* player = iPdPlaybackUtility->PlayerManager().CurrentPlayer(); |
|
376 TUid pluginUid( KNullUid ); |
|
377 RArray<TUid> array; |
|
378 CleanupClosePushL( array ); |
|
379 if ( player ) |
|
380 { |
|
381 pluginUid = player->UidL(); |
|
382 array.AppendL( pluginUid ); |
|
383 } |
|
384 array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid )); |
|
385 iViewUtility->ActivateViewL( array ); |
|
386 CleanupStack::PopAndDestroy( &array ); |
|
387 } |
|
388 |
|
389 // -------------------------------------------------------------- |
|
390 // CMPXPdCommandHandler::SendCustomCommandToMPXL() |
|
391 // -------------------------------------------------------------- |
|
392 // |
|
393 void CMPXPdCommandHandler::SendCustomCommandToMPXL( |
|
394 TUint aTransactionID, |
|
395 TMPXPlaybackPdCommand aCustomCmd) |
|
396 { |
|
397 MPX_DEBUG2("CMPXPdCommandHandler::SendCustomCommandToMPXL(aEvent=%d) (aCustomCmd=%d)", aCustomCmd); |
|
398 |
|
399 CMPXCommand* cmd( CMPXCommand::NewL() ); |
|
400 CleanupStack::PushL( cmd ); |
|
401 cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue ); |
|
402 cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXCommandIdPlaybackPD ); |
|
403 cmd->SetTObjectValueL<TMPXPlaybackPdCommand>( KMPXCommandPlaybackGeneralType, aCustomCmd ); |
|
404 cmd->SetTObjectValueL<TUint>( KMPXCommandPlaybackPDTransactionID, aTransactionID ); |
|
405 iPdPlaybackUtility->CommandL( *cmd ); |
|
406 CleanupStack::PopAndDestroy( cmd ); |
|
407 } |
|
408 |
|
409 |
|
410 |
|
411 // --------------------------------------------------------------------------- |
|
412 // Handle playback state changed. |
|
413 // --------------------------------------------------------------------------- |
|
414 // |
|
415 void CMPXPdCommandHandler::DoHandleStateChangedL( |
|
416 TMPXPlaybackState aState ) |
|
417 { |
|
418 MPX_DEBUG2( "CMPXPdCommandHandler::DoHandleStateChangedL(%d)", aState ); |
|
419 |
|
420 switch ( aState ) |
|
421 { |
|
422 case EPbStateStopped: |
|
423 { |
|
424 iPlaybackCompleted = ETrue; |
|
425 } |
|
426 break; |
|
427 case EPbStatePaused: |
|
428 { |
|
429 if (iPrevousPlaybackState == EPbStateInitialising) |
|
430 { |
|
431 iPdPlaybackUtility->CommandL( EPbCmdPlay ); //Automatically play when EMC is done initializing. |
|
432 } |
|
433 } |
|
434 break; |
|
435 default: |
|
436 break; |
|
437 } |
|
438 MPX_DEBUG1("CMPXPdCommandHandler::DoHandleStateChangedL()"); |
|
439 } |
|
440 |
|
441 |
|
442 // -------------------------------------------------------------- |
|
443 // CMPXPdCommandHandler::IsPlaybackCompleted() |
|
444 // -------------------------------------------------------------- |
|
445 // |
|
446 TBool CMPXPdCommandHandler::IsPlaybackCompleted() |
|
447 { |
|
448 return iPlaybackCompleted; |
|
449 } |
|
450 // End of File |