|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <mpxmediamusicdefs.h> |
|
22 #include <mpxmediacontainerdefs.h> |
|
23 #include <mpxmessagegeneraldefs.h> |
|
24 #include <pathinfo.h> |
|
25 |
|
26 #include <mpxcollectionhelper.h> |
|
27 #include <mpxcollectionhelperfactory.h> |
|
28 #include <mpxcollectionuihelper.h> |
|
29 #include <mpxcollectionhelperfactory.h> |
|
30 |
|
31 #include <mpxcollectionutility.h> |
|
32 #include <mpxcollectionplaylist.h> |
|
33 #include <mpxcollectionmessage.h> |
|
34 #include <mpxcollectionpath.h> |
|
35 |
|
36 #include "cmtpplaybackcontrolimpl.h" |
|
37 #include "cmtpplaybackplaylisthelper.h" |
|
38 #include "mtpplaybackcontrolpanic.h" |
|
39 |
|
40 // Constants |
|
41 __FLOG_STMT(_LIT8(KComponent,"PlaybackPlaylistHelper");) |
|
42 |
|
43 // ======== MEMBER FUNCTIONS ======== |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CMTPPlaybackPlaylistHelper::NewL |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CMTPPlaybackPlaylistHelper* CMTPPlaybackPlaylistHelper::NewL( CMTPPlaybackControlImpl& aControlImpl ) |
|
50 { |
|
51 CMTPPlaybackPlaylistHelper* self = new ( ELeave ) |
|
52 CMTPPlaybackPlaylistHelper( aControlImpl ); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CMTPPlaybackPlaylistHelper::~CMTPPlaybackPlaylistHelper |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CMTPPlaybackPlaylistHelper::~CMTPPlaybackPlaylistHelper() |
|
64 { |
|
65 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::~CMTPPlaybackPlaylistHelper")); |
|
66 |
|
67 if( iCollectionUiHelper ) |
|
68 { |
|
69 iCollectionUiHelper->Close(); |
|
70 } |
|
71 |
|
72 if ( iCollectionHelper ) |
|
73 { |
|
74 iCollectionHelper->Close(); |
|
75 } |
|
76 |
|
77 if( iCollectionUtil ) |
|
78 { |
|
79 iCollectionUtil->Close(); |
|
80 } |
|
81 |
|
82 delete iPlayObject; |
|
83 |
|
84 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::~CMTPPlaybackPlaylistHelper")); |
|
85 __FLOG_CLOSE; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL |
|
90 //// Get Playlist via aMedia |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL( const TMTPPbDataSuid& aPlayObject ) |
|
94 { |
|
95 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL")); |
|
96 |
|
97 //Reset |
|
98 ResetPlaySource(); |
|
99 |
|
100 iPlayCategory = aPlayObject.Category(); |
|
101 iPlayObject = aPlayObject.Suid().AllocL(); |
|
102 |
|
103 switch ( iPlayCategory ) |
|
104 { |
|
105 case EMTPPbCatPlayList: |
|
106 { |
|
107 OpenMusicPlayListPathL(); |
|
108 } |
|
109 break; |
|
110 case EMTPPbCatAlbum: |
|
111 { |
|
112 OpenMusicAblumPathL(); |
|
113 } |
|
114 break; |
|
115 default: |
|
116 { |
|
117 Panic( EMTPPBCollectionErrCall ); |
|
118 } |
|
119 break; |
|
120 } |
|
121 |
|
122 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL")); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL |
|
127 // Get Playlist via index |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL( TInt aIndex ) |
|
131 { |
|
132 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL")); |
|
133 |
|
134 iSongIndex = aIndex; |
|
135 |
|
136 UpdatePathAndOpenL(); |
|
137 |
|
138 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL")); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CMTPPlaybackPlaylistHelper::GetMTPPBSuidFromCollectionL |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 TMTPPbDataSuid CMTPPlaybackPlaylistHelper::GetMTPPBSuidFromCollectionL( |
|
146 const CMPXCollectionPlaylist& aPlaylist ) |
|
147 { |
|
148 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL")); |
|
149 |
|
150 CMPXCollectionPath* path = iCollectionUiHelper->MusicPlaylistPathL(); |
|
151 if ( path->Id() == aPlaylist.Path().Id( KMTPPlaybackPlaylistAblumLevel -1 )) |
|
152 { |
|
153 iPlayCategory = EMTPPbCatPlayList; |
|
154 } |
|
155 else |
|
156 { |
|
157 iPlayCategory = EMTPPbCatAlbum; |
|
158 } |
|
159 TFileName uri = ItemIdToUriL( aPlaylist.Path().Id( KMTPPlaybackPlaylistAblumLevel )); |
|
160 TMTPPbDataSuid dataSuid( iPlayCategory, uri ); |
|
161 |
|
162 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::GetPlayListFromCollectionL")); |
|
163 return dataSuid; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CMTPPlaybackPlaylistHelper::MTPPbCategory |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 TMTPPbCategory CMTPPlaybackPlaylistHelper::MTPPbCategory() const |
|
171 { |
|
172 return iPlayCategory; |
|
173 } |
|
174 // --------------------------------------------------------------------------- |
|
175 // CMTPPlaybackPlaylistHelper::MTPPbSuid |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 TFileName CMTPPlaybackPlaylistHelper::MTPPbSuid() const |
|
179 { |
|
180 return TFileName( *iPlayObject ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // From MMPXCollectionObserver |
|
185 // Handle completion of a asynchronous command |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 void CMTPPlaybackPlaylistHelper::HandleCollectionMessage( CMPXMessage* aMsg, TInt aErr ) |
|
189 { |
|
190 __FLOG_1(_L8("+CMTPPlaybackPlaylistHelper::HandleCollectionMessage( %d ) "), aErr ); |
|
191 |
|
192 if (( KErrNone == aErr ) && aMsg ) |
|
193 { |
|
194 TRAP( aErr, DoHandleCollectionMessageL( *aMsg )); |
|
195 } |
|
196 |
|
197 if ( KErrNone != aErr ) |
|
198 { |
|
199 TInt error = MTPPlaybackControlImpl().MapError( aErr ); |
|
200 MTPPlaybackControlImpl().DoHandleError( error ); |
|
201 } |
|
202 |
|
203 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::HandleCollectionMessage")); |
|
204 } |
|
205 // --------------------------------------------------------------------------- |
|
206 // From MMPXCollectionObserver |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CMTPPlaybackPlaylistHelper::HandleOpenL( const CMPXMedia& aEntries, |
|
210 TInt /*aIndex*/, TBool /*aComplete*/, TInt aError ) |
|
211 { |
|
212 __FLOG_1(_L8("+CMTPPlaybackPlaylistHelper::HandleOpenL( %d )"), aError ); |
|
213 |
|
214 if ( KErrNone == aError ) |
|
215 { |
|
216 TRAP( aError, DoHandleOpenL( aEntries )); |
|
217 } |
|
218 |
|
219 if ( KErrNone != aError ) |
|
220 { |
|
221 TInt error = MTPPlaybackControlImpl().MapError( aError ); |
|
222 MTPPlaybackControlImpl().DoHandleError( error ); |
|
223 } |
|
224 |
|
225 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::HandleOpenL")); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // From MMPXCollectionObserver |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void CMTPPlaybackPlaylistHelper::HandleOpenL( const CMPXCollectionPlaylist& aPlaylist, |
|
233 TInt aError ) |
|
234 { |
|
235 __FLOG_1(_L8("+CMTPPlaybackPlaylistHelper::HandleOpenL( aPlaylist, aError = %d )"), aError ); |
|
236 |
|
237 if ( KErrNone == aError ) |
|
238 { |
|
239 TRAP( aError, MTPPlaybackControlImpl().GetPlaylistFromCollectionCompleteL( aPlaylist )); |
|
240 } |
|
241 |
|
242 if ( KErrNone != aError ) |
|
243 { |
|
244 TInt error = MTPPlaybackControlImpl().MapError( aError ); |
|
245 MTPPlaybackControlImpl().DoHandleError( error ); |
|
246 } |
|
247 |
|
248 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::HandleOpenL( aPlaylist, aError )")); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // From MMPXCollectionMediaObserver |
|
253 // --------------------------------------------------------------------------- |
|
254 void CMTPPlaybackPlaylistHelper::HandleCollectionMediaL( const CMPXMedia& /*aMedia*/, TInt /*aError*/ ) |
|
255 { |
|
256 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::HandleCollectionMediaL")); |
|
257 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::HandleCollectionMediaL")); |
|
258 } |
|
259 |
|
260 // |
|
261 // CMTPPlaybackPlaylistHelper::CMTPPlaybackPlaylistHelper |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 CMTPPlaybackPlaylistHelper::CMTPPlaybackPlaylistHelper( CMTPPlaybackControlImpl& aControlImpl ) |
|
265 : iCollectionUiHelper( NULL ), |
|
266 iCollectionHelper( NULL ), |
|
267 iCollectionUtil( NULL ), |
|
268 iPlayObject( NULL ), |
|
269 iMTPPlaybackControl( aControlImpl ) |
|
270 { |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CMTPPlaybackPlaylistHelper::ConstructL |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CMTPPlaybackPlaylistHelper::ConstructL() |
|
278 { |
|
279 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
280 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::ConstructL")); |
|
281 |
|
282 iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL(); |
|
283 iCollectionUtil = MMPXCollectionUtility::NewL( this, KMcModeDefault ); |
|
284 |
|
285 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::ConstructL")); |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // CMTPPlaybackPlaylistHelper::DoHandleCollectionMessage |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 void CMTPPlaybackPlaylistHelper::DoHandleCollectionMessageL( const CMPXMessage& aMsg ) |
|
293 { |
|
294 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::DoHandleCollectionMessage")); |
|
295 |
|
296 TMPXMessageId id( aMsg.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
297 |
|
298 if ( KMPXMessageGeneral == id ) |
|
299 { |
|
300 TInt event( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ); |
|
301 TInt type( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralType ) ); |
|
302 TInt data( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralData ) ); |
|
303 |
|
304 __FLOG_VA((_L8("Event code is 0x%X, type code is 0x%X"), event, type )); |
|
305 __FLOG_1(_L8("Data code is 0x%X"), data ); |
|
306 |
|
307 if ( event == TMPXCollectionMessage::EPathChanged && |
|
308 type == EMcPathChangedByOpen && |
|
309 data == EMcContainerOpened ) |
|
310 { |
|
311 iCollectionUtil->Collection().OpenL(); |
|
312 } |
|
313 else if ( event == TMPXCollectionMessage::EPathChanged && |
|
314 type == EMcPathChangedByOpen && |
|
315 data == EMcItemOpened ) |
|
316 { |
|
317 iCollectionUtil->Collection().OpenL(); |
|
318 } |
|
319 else if ( event == TMPXCollectionMessage::ECollectionChanged ) |
|
320 { |
|
321 __FLOG(_L8("Ignore this event")); |
|
322 } |
|
323 } |
|
324 |
|
325 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::DoHandleCollectionMessage")); |
|
326 } |
|
327 |
|
328 // ---------------------------------------------------- |
|
329 // CMTPPlaybackPlaylistHelper::DoHandleOpenL |
|
330 // ---------------------------------------------------- |
|
331 // |
|
332 void CMTPPlaybackPlaylistHelper::DoHandleOpenL( const CMPXMedia& aEntries ) |
|
333 { |
|
334 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::DoHandleOpenL( const CMPXMedia )")); |
|
335 |
|
336 if ( EMTPPbCatAlbum == iPlayCategory ) |
|
337 { |
|
338 UpdateAlbumPathAndOpenL(); |
|
339 } |
|
340 else |
|
341 { |
|
342 //playlist |
|
343 if ( -1 == iPathIndex ) |
|
344 { |
|
345 //first, the top path |
|
346 UpdatePlaylistPathIndexL( aEntries ); |
|
347 |
|
348 if ( -1 == iPathIndex ) |
|
349 { |
|
350 MTPPlaybackControlImpl().DoHandleError( KPlaybackErrParamInvalid ); |
|
351 } |
|
352 else |
|
353 { |
|
354 iCollectionUtil->Collection().OpenL( iPathIndex ); |
|
355 } |
|
356 } |
|
357 else |
|
358 { |
|
359 //open the first song when initObject |
|
360 iCollectionUtil->Collection().OpenL( iSongIndex ); |
|
361 } |
|
362 } |
|
363 |
|
364 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::DoHandleOpenL( const CMPXMedia )")); |
|
365 } |
|
366 |
|
367 // ---------------------------------------------------- |
|
368 // CMTPPlaybackPlaylistHelper::OpenMusicPlayListPathL |
|
369 // ---------------------------------------------------- |
|
370 // |
|
371 void CMTPPlaybackPlaylistHelper::OpenMusicPlayListPathL() |
|
372 { |
|
373 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::OpenMusicPlayListPathL")); |
|
374 |
|
375 CMPXCollectionPath* path = iCollectionUiHelper->MusicPlaylistPathL(); |
|
376 CleanupStack::PushL( path ); |
|
377 iCollectionUtil->Collection().OpenL( *path ); |
|
378 CleanupStack::PopAndDestroy( path ); |
|
379 |
|
380 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::OpenMusicPlayListPathL")); |
|
381 } |
|
382 |
|
383 // ---------------------------------------------------- |
|
384 // CMTPPlaybackPlaylistHelper::OpenMusicAblumPathL |
|
385 // ---------------------------------------------------- |
|
386 // |
|
387 void CMTPPlaybackPlaylistHelper::OpenMusicAblumPathL() |
|
388 { |
|
389 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::OpenMusicAblumPathL")); |
|
390 |
|
391 CMPXCollectionPath* path = iCollectionUiHelper->MusicMenuPathL(); |
|
392 CleanupStack::PushL( path ); |
|
393 path->AppendL(KMPXCollectionArtistAlbum); |
|
394 iCollectionUtil->Collection().OpenL( *path ); |
|
395 CleanupStack::PopAndDestroy( path ); |
|
396 |
|
397 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::OpenMusicAblumPathL")); |
|
398 } |
|
399 |
|
400 // ---------------------------------------------------- |
|
401 // CMTPPlaybackPlaylistHelper::ResetPlaySource |
|
402 // ---------------------------------------------------- |
|
403 // |
|
404 void CMTPPlaybackPlaylistHelper::ResetPlaySource() |
|
405 { |
|
406 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::ResetPlaySourceL")); |
|
407 |
|
408 iPathIndex = -1; |
|
409 iSongIndex = 0; |
|
410 delete iPlayObject; |
|
411 iPlayObject = NULL; |
|
412 |
|
413 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::ResetPlaySourceL")); |
|
414 } |
|
415 |
|
416 // ---------------------------------------------------- |
|
417 // CMTPPlaybackPlaylistHelper::UpdatePlaylistPathIndexL |
|
418 // ---------------------------------------------------- |
|
419 // |
|
420 void CMTPPlaybackPlaylistHelper::UpdatePlaylistPathIndexL( const CMPXMedia& aEntries ) |
|
421 { |
|
422 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::UpdatePlaylistPathIndexL")); |
|
423 __ASSERT_DEBUG( iPlayCategory == EMTPPbCatPlayList, Panic( EMTPPBCollectionErrCall )); |
|
424 |
|
425 const CMPXMediaArray* refArray = aEntries.Value<CMPXMediaArray> ( KMPXMediaArrayContents ); |
|
426 TInt count = refArray->Count(); |
|
427 const TMPXItemId playlistId = UriToItemIdL(); |
|
428 |
|
429 for ( TInt i=0; i<count; ++i ) |
|
430 { |
|
431 CMPXMedia* container = refArray->AtL(i); |
|
432 /** |
|
433 * Try to find out the next path according to the |
|
434 * playlist's ItemId |
|
435 */ |
|
436 if ( container->IsSupported( KMPXMediaGeneralId )) |
|
437 { |
|
438 const TMPXItemId tempId = container->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
439 if ( tempId == playlistId ) |
|
440 { |
|
441 iPathIndex = i; |
|
442 break; |
|
443 } |
|
444 } |
|
445 } |
|
446 |
|
447 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::UpdatePlaylistPathIndexL")); |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // return instance of CollectionHelper. |
|
452 // --------------------------------------------------------------------------- |
|
453 // |
|
454 MMPXCollectionHelper* CMTPPlaybackPlaylistHelper::CollectionHelperL() |
|
455 { |
|
456 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::CollectionHelperL")); |
|
457 |
|
458 if ( iCollectionHelper == NULL ) |
|
459 { |
|
460 iCollectionHelper = CMPXCollectionHelperFactory::NewCollectionCachedHelperL(); |
|
461 |
|
462 // Do a search for a song ID that does not exist |
|
463 RArray<TInt> contentIDs; |
|
464 CleanupClosePushL( contentIDs ); // + contentIDs |
|
465 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
466 |
|
467 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
468 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
469 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
470 |
|
471 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
472 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong ); |
|
473 searchMedia->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, |
|
474 KMTPPlaybackInvalidSongID ); |
|
475 |
|
476 /* |
|
477 * store root |
|
478 */ |
|
479 TChar driveChar = 'c'; |
|
480 TInt driveNumber; |
|
481 User::LeaveIfError( RFs::CharToDrive( driveChar, driveNumber ) ); |
|
482 |
|
483 // get root path |
|
484 TBuf<KStorageRootMaxLength> storeRoot; |
|
485 User::LeaveIfError( PathInfo::GetRootPath( storeRoot, driveNumber ) ); |
|
486 |
|
487 searchMedia->SetTextValueL( KMPXMediaGeneralDrive, storeRoot ); |
|
488 |
|
489 RArray<TMPXAttribute> songAttributes; |
|
490 CleanupClosePushL( songAttributes ); // + songAttributes |
|
491 songAttributes.AppendL( KMPXMediaGeneralId ); |
|
492 |
|
493 CMPXMedia* foundMedia = NULL; |
|
494 TRAPD( err, foundMedia = iCollectionHelper->FindAllL( |
|
495 *searchMedia, |
|
496 songAttributes.Array() ) ); |
|
497 |
|
498 CleanupStack::PopAndDestroy( &songAttributes ); // - songAttributes |
|
499 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
500 |
|
501 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
502 |
|
503 if ( err != KErrNone ) |
|
504 { |
|
505 iCollectionHelper->Close(); |
|
506 iCollectionHelper = NULL; |
|
507 User::Leave( KErrGeneral ); |
|
508 } |
|
509 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
510 } |
|
511 |
|
512 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::CollectionHelperL")); |
|
513 return iCollectionHelper; |
|
514 } |
|
515 |
|
516 // --------------------------------------------------------------------------- |
|
517 // CMTPPlaybackPlaylistHelper::UriToItemIdL |
|
518 // --------------------------------------------------------------------------- |
|
519 // |
|
520 const TMPXItemId CMTPPlaybackPlaylistHelper::UriToItemIdL() |
|
521 { |
|
522 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::UriToItemIdL")); |
|
523 |
|
524 |
|
525 TMPXItemId itemId( KMPXInvalidItemId ); |
|
526 TInt error = KErrNone; |
|
527 CMPXMedia* result = NULL; |
|
528 |
|
529 RArray<TMPXAttribute> atts; |
|
530 CleanupClosePushL( atts ); |
|
531 atts.AppendL( KMPXMediaGeneralId ); |
|
532 |
|
533 if ( EMTPPbCatPlayList == iPlayCategory ) |
|
534 { |
|
535 TRAP( error, result = CollectionHelperL()->GetL( *iPlayObject, atts.Array(), EMPXPlaylist )); |
|
536 } |
|
537 else |
|
538 { |
|
539 TRAP( error, result = CollectionHelperL()->GetL( *iPlayObject, atts.Array(), EMPXAbstractAlbum )); |
|
540 } |
|
541 |
|
542 if ( error != KErrNone ) |
|
543 { |
|
544 CleanupStack::PopAndDestroy( &atts ); |
|
545 } |
|
546 else |
|
547 { |
|
548 CleanupStack::PushL( result ); |
|
549 itemId = result->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
550 CleanupStack::PopAndDestroy( result ); |
|
551 CleanupStack::PopAndDestroy( &atts ); |
|
552 } |
|
553 |
|
554 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::UriToItemIdL")); |
|
555 return itemId; |
|
556 } |
|
557 |
|
558 // --------------------------------------------------------------------------- |
|
559 // CMTPPlaybackPlaylistHelper::ItemIdToUriL. |
|
560 // --------------------------------------------------------------------------- |
|
561 // |
|
562 const TFileName CMTPPlaybackPlaylistHelper::ItemIdToUriL( const TMPXItemId& aId ) |
|
563 { |
|
564 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::ItemIdToUriL")); |
|
565 |
|
566 TFileName itemUri( KNullDesC ); |
|
567 |
|
568 RArray<TInt> contentIDs; |
|
569 CleanupClosePushL( contentIDs ); // + contentIDs |
|
570 contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
571 |
|
572 CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() ); |
|
573 CleanupStack::PopAndDestroy( &contentIDs ); // - contentIDs |
|
574 CleanupStack::PushL( searchMedia ); // + searchMedia |
|
575 |
|
576 searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); |
|
577 if ( iPlayCategory == EMTPPbCatPlayList ) |
|
578 { |
|
579 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
580 } |
|
581 else |
|
582 { |
|
583 searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXAbstractAlbum ); |
|
584 } |
|
585 searchMedia->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, aId ); |
|
586 |
|
587 RArray<TMPXAttribute> resultAttributes; |
|
588 CleanupClosePushL( resultAttributes ); // + resultAttributes |
|
589 resultAttributes.AppendL( KMPXMediaGeneralUri ); |
|
590 |
|
591 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( |
|
592 *searchMedia, |
|
593 resultAttributes.Array() ); |
|
594 |
|
595 CleanupStack::PopAndDestroy( &resultAttributes ); // - resultAttributes |
|
596 CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia |
|
597 |
|
598 CleanupStack::PushL( foundMedia ); // + foundMedia |
|
599 if ( !foundMedia->IsSupported( KMPXMediaArrayCount )) |
|
600 { |
|
601 User::Leave( KErrNotSupported ); |
|
602 } |
|
603 else if ( *foundMedia->Value<TInt>( KMPXMediaArrayCount ) != 1 ) |
|
604 { |
|
605 User::Leave( KErrNotSupported ); |
|
606 } |
|
607 |
|
608 const CMPXMediaArray* tracksArray = foundMedia->Value<CMPXMediaArray> ( KMPXMediaArrayContents ); |
|
609 CMPXMedia* item = tracksArray->AtL(0); |
|
610 |
|
611 if ( item->IsSupported( KMPXMediaGeneralUri )) |
|
612 { |
|
613 itemUri = item->ValueText(KMPXMediaGeneralUri); |
|
614 } |
|
615 |
|
616 CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia |
|
617 |
|
618 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::ItemIdToUriL")); |
|
619 return itemUri; |
|
620 } |
|
621 |
|
622 // --------------------------------------------------------------------------- |
|
623 // CMTPPlaybackPlaylistHelper::FindAlbumSongsL |
|
624 // --------------------------------------------------------------------------- |
|
625 // |
|
626 CMPXMedia* CMTPPlaybackPlaylistHelper::FindAlbumSongsL( const TMPXItemId& aAlbumId ) |
|
627 { |
|
628 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::FindAlbumSongsL")); |
|
629 |
|
630 // Fetch the songs for the selected album |
|
631 CMPXMedia* findCriteria = CMPXMedia::NewL(); |
|
632 CleanupStack::PushL( findCriteria ); |
|
633 findCriteria->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXGroup ); |
|
634 findCriteria->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXSong ); |
|
635 findCriteria->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, aAlbumId ); |
|
636 RArray<TMPXAttribute> attrs; |
|
637 CleanupClosePushL( attrs ); |
|
638 attrs.Append( TMPXAttribute( KMPXMediaIdGeneral, |
|
639 EMPXMediaGeneralTitle | |
|
640 EMPXMediaGeneralId ) ); |
|
641 attrs.Append( KMPXMediaMusicAlbumTrack ); |
|
642 |
|
643 CMPXMedia* foundMedia = CollectionHelperL()->FindAllL( *findCriteria, |
|
644 attrs.Array() ); |
|
645 CleanupStack::PopAndDestroy( &attrs ); |
|
646 CleanupStack::PopAndDestroy( findCriteria ); |
|
647 |
|
648 if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) ) |
|
649 { |
|
650 User::Leave( KErrNotSupported ); |
|
651 } |
|
652 TInt foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount ); |
|
653 if ( foundItemCount == 0 ) |
|
654 { |
|
655 User::Leave( KErrNotFound ); |
|
656 } |
|
657 if ( !foundMedia->IsSupported( KMPXMediaArrayContents ) ) |
|
658 { |
|
659 User::Leave( KErrNotSupported ); |
|
660 } |
|
661 |
|
662 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::FindAlbumSongsL")); |
|
663 return foundMedia; |
|
664 } |
|
665 |
|
666 // --------------------------------------------------------------------------- |
|
667 // CMTPPlaybackPlaylistHelper::UpdatePathAndOpenL. |
|
668 // aParam: const CMPXMedia& aAlbums |
|
669 // --------------------------------------------------------------------------- |
|
670 // |
|
671 void CMTPPlaybackPlaylistHelper::UpdateAlbumPathAndOpenL() |
|
672 { |
|
673 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::UpdateAlbumPathAndOpenL")); |
|
674 |
|
675 RArray<TMPXItemId> ids; |
|
676 CleanupClosePushL(ids); |
|
677 |
|
678 CMPXCollectionPath* cpath = iCollectionUtil->Collection().PathL(); |
|
679 CleanupStack::PushL( cpath ); |
|
680 |
|
681 if (cpath->Levels() == 3) |
|
682 { |
|
683 // go back one level before amending path with new levels |
|
684 cpath->Back(); |
|
685 } |
|
686 |
|
687 const TMPXItemId id = UriToItemIdL(); |
|
688 if ( KMPXInvalidItemId == id ) |
|
689 { |
|
690 MTPPlaybackControlImpl().DoHandleError( KPlaybackErrParamInvalid ); |
|
691 CleanupStack::PopAndDestroy( cpath ); |
|
692 CleanupStack::PopAndDestroy(&ids); |
|
693 return; |
|
694 } |
|
695 |
|
696 ids.AppendL(id); |
|
697 cpath->AppendL( ids.Array() ); // top level items |
|
698 cpath->Set( 0 ); |
|
699 ids.Reset(); |
|
700 |
|
701 CMPXMedia* songs = FindAlbumSongsL( id ); |
|
702 CleanupStack::PushL( songs ); |
|
703 const CMPXMediaArray* tracksArray = songs->Value<CMPXMediaArray> ( KMPXMediaArrayContents ); |
|
704 User::LeaveIfNull(const_cast<CMPXMediaArray*>(tracksArray)); |
|
705 TUint count = tracksArray->Count(); |
|
706 for (TInt i=0; i<count; ++i) |
|
707 { |
|
708 CMPXMedia* song = tracksArray->AtL(i); |
|
709 const TMPXItemId id = song->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
710 ids.AppendL(id); |
|
711 } |
|
712 |
|
713 cpath->AppendL(ids.Array()); // top level items |
|
714 cpath->Set( iSongIndex ); |
|
715 |
|
716 iCollectionUtil->Collection().OpenL(*cpath); |
|
717 CleanupStack::PopAndDestroy( songs ); |
|
718 CleanupStack::PopAndDestroy( cpath ); |
|
719 CleanupStack::PopAndDestroy(&ids); |
|
720 |
|
721 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::UpdateAlbumPathAndOpenL")); |
|
722 } |
|
723 |
|
724 // --------------------------------------------------------------------------- |
|
725 // CMTPPlaybackPlaylistHelper::UpdatePathAndOpenL. |
|
726 // --------------------------------------------------------------------------- |
|
727 // |
|
728 void CMTPPlaybackPlaylistHelper::UpdatePathAndOpenL() |
|
729 { |
|
730 __FLOG(_L8("+CMTPPlaybackPlaylistHelper::UpdatePathAndOpenL()")); |
|
731 |
|
732 RArray<TMPXItemId> ids; |
|
733 CleanupClosePushL(ids); |
|
734 |
|
735 CMPXCollectionPath* cpath = iCollectionUtil->Collection().PathL(); |
|
736 CleanupStack::PushL( cpath ); |
|
737 |
|
738 cpath->Set( iSongIndex ); |
|
739 |
|
740 iCollectionUtil->Collection().OpenL(*cpath); |
|
741 CleanupStack::PopAndDestroy( cpath ); |
|
742 CleanupStack::PopAndDestroy(&ids); |
|
743 |
|
744 __FLOG(_L8("-CMTPPlaybackPlaylistHelper::UpdatePathAndOpenL( aSong Index )")); |
|
745 } |
|
746 |
|
747 // --------------------------------------------------------------------------- |
|
748 // CMTPPlaybackPlaylistHelper::MTPPlaybackControlImpl. |
|
749 // --------------------------------------------------------------------------- |
|
750 // |
|
751 CMTPPlaybackControlImpl& CMTPPlaybackPlaylistHelper::MTPPlaybackControlImpl() |
|
752 { |
|
753 return iMTPPlaybackControl; |
|
754 } |
|
755 |
|
756 |