author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:28:40 +0300 | |
branch | RCL_3 |
changeset 66 | 1f1dad4af8f8 |
parent 53 | 3de6c4cf6b67 |
permissions | -rw-r--r-- |
53 | 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: Helper to construct a collection playlist. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// INCLUDE FILES |
|
20 |
#include <bldvariant.hrh> |
|
21 |
#include <s32file.h> |
|
22 |
#include <e32math.h> |
|
23 |
#include <mpxcollectionframeworkdefs.h> |
|
24 |
#include <mpxcollectionmessage.h> |
|
25 |
#include <mpxcollectionutility.h> |
|
26 |
#include <mpxcollectionplaylist.h> |
|
27 |
#include <mpxcollectionpath.h> |
|
28 |
#include <mpxcollectionuihelper.h> |
|
29 |
#include <mpxplaybackutility.h> |
|
30 |
#include <mpxplaybackmessage.h> |
|
31 |
#include <mpxmessagegeneraldefs.h> |
|
32 |
#include <mpxplaybackmessagedefs.h> |
|
33 |
#include <mpxcollectionopenutility.h> |
|
34 |
#include <mpxconstants.h> |
|
35 |
||
36 |
#include "mpxcollectionviewhgplaylisthelper.h" |
|
37 |
#include "mpxlog.h" |
|
38 |
||
39 |
// CONSTANTS |
|
40 |
const TInt KIncrementalFetchCount = 400; |
|
41 |
const TInt KIncrementalNullOffset = 0; |
|
42 |
||
43 |
// ============================ MEMBER FUNCTIONS ============================== |
|
44 |
||
45 |
// ---------------------------------------------------------------------------- |
|
46 |
// Two-phased constructor. |
|
47 |
// ---------------------------------------------------------------------------- |
|
48 |
// |
|
49 |
CMPXCollectionViewHgPlaylistHelper* CMPXCollectionViewHgPlaylistHelper::NewL( |
|
50 |
MMPXPlaybackUtility* aPlaybackUtility, |
|
51 |
MMPXCollectionUiHelper* aCollectionUiHelper) |
|
52 |
{ |
|
53 |
CMPXCollectionViewHgPlaylistHelper* self = NewLC(aPlaybackUtility, aCollectionUiHelper); |
|
54 |
CleanupStack::Pop(self); |
|
55 |
return self; |
|
56 |
} |
|
57 |
||
58 |
// ---------------------------------------------------------------------------- |
|
59 |
// Two-phased constructor. |
|
60 |
// ---------------------------------------------------------------------------- |
|
61 |
// |
|
62 |
CMPXCollectionViewHgPlaylistHelper* CMPXCollectionViewHgPlaylistHelper::NewLC( |
|
63 |
MMPXPlaybackUtility* aPlaybackUtility, |
|
64 |
MMPXCollectionUiHelper* aCollectionUiHelper ) |
|
65 |
{ |
|
66 |
CMPXCollectionViewHgPlaylistHelper* self = |
|
67 |
new (ELeave) CMPXCollectionViewHgPlaylistHelper(aPlaybackUtility, |
|
68 |
aCollectionUiHelper); |
|
69 |
CleanupStack::PushL(self); |
|
70 |
self->ConstructL(); |
|
71 |
return self; |
|
72 |
} |
|
73 |
||
74 |
// ---------------------------------------------------------------------------- |
|
75 |
// C++ constructor can NOT contain any code that might leave. |
|
76 |
// ---------------------------------------------------------------------------- |
|
77 |
// |
|
78 |
CMPXCollectionViewHgPlaylistHelper::CMPXCollectionViewHgPlaylistHelper( |
|
79 |
MMPXPlaybackUtility* aPlaybackUtility, |
|
80 |
MMPXCollectionUiHelper* aCollectionUiHelper ) |
|
81 |
: iPlaybackUtility(aPlaybackUtility), |
|
82 |
iCollectionUiHelper( aCollectionUiHelper ), |
|
83 |
iPathInitialized(0), |
|
84 |
iIsInitializing(EFalse), |
|
85 |
iInitCanceled(EFalse), |
|
86 |
iLoadSavedPath(EFalse), |
|
87 |
iEnableShuffle(EFalse) |
|
88 |
{ |
|
89 |
} |
|
90 |
||
91 |
// ---------------------------------------------------------------------------- |
|
92 |
// Destructor. |
|
93 |
// ---------------------------------------------------------------------------- |
|
94 |
// |
|
95 |
CMPXCollectionViewHgPlaylistHelper::~CMPXCollectionViewHgPlaylistHelper() |
|
96 |
{ |
|
97 |
if ( iCollectionUtility ) |
|
98 |
{ |
|
99 |
iCollectionUtility->Close(); |
|
100 |
} |
|
101 |
||
102 |
delete iIncOpenUtil; |
|
103 |
} |
|
104 |
||
105 |
// ---------------------------------------------------------------------------- |
|
106 |
// Symbian 2nd phase constructor can leave. |
|
107 |
// ---------------------------------------------------------------------------- |
|
108 |
// |
|
109 |
void CMPXCollectionViewHgPlaylistHelper::ConstructL() |
|
110 |
{ |
|
111 |
iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated ); |
|
112 |
iIncOpenUtil = CMPXCollectionOpenUtility::NewL( this, KMcModeIsolated ); |
|
113 |
} |
|
114 |
||
115 |
||
116 |
// --------------------------------------------------------------------------- |
|
117 |
// Create the default path and load it in collection |
|
118 |
// --------------------------------------------------------------------------- |
|
119 |
// |
|
120 |
void CMPXCollectionViewHgPlaylistHelper::LoadDefaultPathL( TInt aDelay ) |
|
121 |
{ |
|
122 |
MPX_DEBUG1("CMPXCollectionViewHgPlaylistHelper::LoadDefaultPathL"); |
|
123 |
CMPXCollectionPath* cpath = iCollectionUiHelper->CreateDefaultPlaylistPathLC(); |
|
124 |
||
125 |
if (!iIsInitializing) |
|
126 |
{ |
|
127 |
// Get incremental utility to open the path |
|
128 |
// |
|
129 |
DoIncrementalOpenL( *cpath, KIncrementalNullOffset, aDelay ); |
|
130 |
||
131 |
iPathInitialized = EFalse; |
|
132 |
iIsInitializing = ETrue; |
|
133 |
iInitCanceled = EFalse; |
|
134 |
iDefaultPath = ETrue; |
|
135 |
iSelectionId = KMPXInvalidItemId; |
|
136 |
} |
|
137 |
CleanupStack::PopAndDestroy( cpath ); |
|
138 |
} |
|
139 |
||
140 |
// --------------------------------------------------------------------------- |
|
141 |
// Create playlist from default path. |
|
142 |
// --------------------------------------------------------------------------- |
|
143 |
// |
|
144 |
void CMPXCollectionViewHgPlaylistHelper::InitPlaylistL(TBool aEnableShuffle) |
|
145 |
{ |
|
146 |
MPX_DEBUG1("CMPXCollectionViewHgPlaylistHelper::InitPlaylistL"); |
|
147 |
CMPXCollectionPath* cpath = iCollectionUiHelper->CreateDefaultPlaylistPathLC(); |
|
148 |
||
149 |
if (!iIsInitializing) |
|
150 |
{ |
|
151 |
// Get incremental utility to open the path |
|
152 |
// |
|
153 |
DoIncrementalOpenL( *cpath, KIncrementalNullOffset, 0 ); |
|
154 |
||
155 |
iPathInitialized = EFalse; |
|
156 |
iIsInitializing = ETrue; |
|
157 |
iInitCanceled = EFalse; |
|
158 |
iDefaultPath = ETrue; |
|
159 |
iSelectionId = KMPXInvalidItemId; |
|
160 |
iEnableShuffle = aEnableShuffle; |
|
161 |
} |
|
162 |
CleanupStack::PopAndDestroy( cpath ); |
|
163 |
} |
|
164 |
||
165 |
// --------------------------------------------------------------------------- |
|
166 |
// Create playlist from provided path |
|
167 |
// --------------------------------------------------------------------------- |
|
168 |
// |
|
169 |
void CMPXCollectionViewHgPlaylistHelper::InitPlaylistL(CMPXCollectionPath& aPath, TBool aEnableShuffle) |
|
170 |
{ |
|
171 |
MPX_DEBUG1("CMPXCollectionViewHgPlaylistHelper::InitPlaylistL"); |
|
172 |
||
173 |
if (!iIsInitializing) |
|
174 |
{ |
|
175 |
if (aEnableShuffle) |
|
176 |
{ |
|
177 |
TTime time; |
|
178 |
time.UniversalTime(); |
|
179 |
TInt64 seed = time.Int64(); |
|
180 |
TInt randIndex = Math::Rand(seed) % aPath.Count(); |
|
181 |
aPath.Set(randIndex); |
|
182 |
} |
|
183 |
||
184 |
CMPXCollectionPlaylist* playlist = CMPXCollectionPlaylist::NewL( aPath ); |
|
185 |
CleanupStack::PushL( playlist ); |
|
186 |
||
66
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
187 |
playlist->SetShuffleEnabledL( aEnableShuffle ); |
53 | 188 |
iPlaybackUtility->SetL( EPbPropertyRandomMode, aEnableShuffle ); |
189 |
iPlaybackUtility->InitL( *playlist, ETrue ); |
|
190 |
CleanupStack::PopAndDestroy( playlist ); |
|
191 |
||
192 |
//iPlaybackUtility->SetL( EPbPropertyRandomMode, aEnableShuffle ); |
|
193 |
//iCollectionUtility->Collection().OpenL(aPath); |
|
194 |
||
195 |
iPathInitialized = ETrue; |
|
196 |
iInitCanceled = EFalse; |
|
197 |
iDefaultPath = EFalse; |
|
198 |
iSelectionId = KMPXInvalidItemId; |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
||
203 |
// --------------------------------------------------------------------------- |
|
204 |
// Check the initialized flag |
|
205 |
// --------------------------------------------------------------------------- |
|
206 |
// |
|
207 |
TBool CMPXCollectionViewHgPlaylistHelper::Initialized() |
|
208 |
{ |
|
209 |
return iPathInitialized; |
|
210 |
} |
|
211 |
||
212 |
// --------------------------------------------------------------------------- |
|
213 |
// Check the iIsInitializing flag |
|
214 |
// --------------------------------------------------------------------------- |
|
215 |
// |
|
216 |
TBool CMPXCollectionViewHgPlaylistHelper::IsInitializing() |
|
217 |
{ |
|
218 |
return iIsInitializing; |
|
219 |
} |
|
220 |
||
221 |
// --------------------------------------------------------------------------- |
|
222 |
// Set the initialized flag |
|
223 |
// --------------------------------------------------------------------------- |
|
224 |
// |
|
225 |
void CMPXCollectionViewHgPlaylistHelper::SetInitialized( TBool aInit ) |
|
226 |
{ |
|
227 |
iPathInitialized = aInit; |
|
228 |
iIsInitializing = EFalse; |
|
229 |
} |
|
230 |
||
231 |
// --------------------------------------------------------------------------- |
|
232 |
// Cancels the initialize operation |
|
233 |
// --------------------------------------------------------------------------- |
|
234 |
// |
|
235 |
void CMPXCollectionViewHgPlaylistHelper::CancelInit() |
|
236 |
{ |
|
237 |
iInitCanceled = ETrue; |
|
238 |
SetInitialized( ETrue ); |
|
239 |
} |
|
240 |
||
241 |
// --------------------------------------------------------------------------- |
|
242 |
// From MMPXCollectionObserver. |
|
243 |
// Handle media properties. |
|
244 |
// --------------------------------------------------------------------------- |
|
245 |
// |
|
246 |
void CMPXCollectionViewHgPlaylistHelper::HandleCollectionMediaL( |
|
247 |
const CMPXMedia& /*aMedia*/, |
|
248 |
TInt /*aError*/ ) |
|
249 |
{ |
|
250 |
// Do nothing |
|
251 |
} |
|
252 |
||
253 |
// --------------------------------------------------------------------------- |
|
254 |
// From MMPXCollectionObserver. |
|
255 |
// Handle collection message. |
|
256 |
// --------------------------------------------------------------------------- |
|
257 |
// |
|
258 |
void CMPXCollectionViewHgPlaylistHelper::HandleCollectionMessage( |
|
259 |
CMPXMessage* aMessage, TInt aError ) |
|
260 |
{ |
|
261 |
if ( aError == KErrNone && aMessage ) |
|
262 |
{ |
|
263 |
TRAP_IGNORE( DoHandleCollectionMessageL( *aMessage ) ); |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
// --------------------------------------------------------------------------- |
|
268 |
// From MMPXCollectionObserver. |
|
269 |
// Handles the collection entries being opened. |
|
270 |
// --------------------------------------------------------------------------- |
|
271 |
// |
|
272 |
void CMPXCollectionViewHgPlaylistHelper::HandleOpenL( |
|
273 |
const CMPXMedia& /* aEntries */, |
|
274 |
TInt /* aIndex */, |
|
275 |
TBool /* aComplete */, |
|
276 |
TInt aError ) |
|
277 |
{ |
|
278 |
// OpenL() callback from trying to open the default Music Menu -> All Songs |
|
279 |
// or from opening a container |
|
280 |
// |
|
281 |
MPX_DEBUG1("CMPXCollectionViewHgPlaylistHelper::HandleOpenL -- Passing path to playback engine"); |
|
282 |
||
283 |
// Stop the incremental open algorithm. We are only interested in fetcing |
|
284 |
// a single block containing the item we want to play. This will speed up the |
|
285 |
// initalization procedure. Once the playlist is created, the playlist |
|
286 |
// takes over the rest of the incremental open operation |
|
287 |
// |
|
288 |
iIncOpenUtil->Stop(); |
|
289 |
if ( aError == KErrNone ) |
|
290 |
{ |
|
291 |
||
292 |
CMPXCollectionPath* cPath = iIncOpenUtil->PathL(); |
|
293 |
CleanupStack::PushL( cPath ); |
|
294 |
InitPlaybackEngineL( *cPath ); |
|
295 |
CleanupStack::PopAndDestroy( cPath ); |
|
296 |
iIsInitializing = EFalse; |
|
297 |
iPathInitialized = ETrue; |
|
298 |
iInitCanceled = EFalse; |
|
299 |
} |
|
300 |
else |
|
301 |
{ |
|
302 |
if( iDefaultPath ) |
|
303 |
{ |
|
304 |
MPX_DEBUG1("CMPXCollectionViewHgPlaylistHelper::HandleOpenL - Failed to open default path"); |
|
305 |
// Failed to open default path, set to initialized |
|
306 |
// "No songs view" |
|
307 |
// |
|
308 |
iDefaultPath = EFalse; |
|
309 |
iPathInitialized = ETrue; |
|
310 |
iIsInitializing = EFalse; |
|
311 |
} |
|
312 |
else |
|
313 |
{ |
|
314 |
MPX_DEBUG1("CMPXCollectionViewHgPlaylistHelper::HandleOpenL - Opening default Path"); |
|
315 |
iIsInitializing = EFalse; |
|
316 |
// Try opening default |
|
317 |
LoadDefaultPathL(); |
|
318 |
} |
|
319 |
} |
|
320 |
} |
|
321 |
||
322 |
// --------------------------------------------------------------------------- |
|
323 |
// Handle playback message. |
|
324 |
// --------------------------------------------------------------------------- |
|
325 |
// |
|
326 |
void CMPXCollectionViewHgPlaylistHelper::HandlePlaybackMessage( |
|
327 |
CMPXMessage* aMessage, TInt aError ) |
|
328 |
{ |
|
329 |
if ( aError == KErrNone && aMessage ) |
|
330 |
{ |
|
331 |
TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
||
336 |
// --------------------------------------------------------------------------- |
|
337 |
// From MMPXCollectionObserver. |
|
338 |
// Handles the item being opened. |
|
339 |
// --------------------------------------------------------------------------- |
|
340 |
// |
|
341 |
void CMPXCollectionViewHgPlaylistHelper::HandleOpenL( |
|
342 |
const CMPXCollectionPlaylist& aPlaylist, |
|
343 |
TInt aError ) |
|
344 |
{ |
|
345 |
MPX_FUNC("CMPXCollectionViewHgPlaylistHelper::HandleOpenL"); |
|
346 |
if( aError == KErrNone ) |
|
347 |
{ |
|
348 |
if ( !iInitCanceled ) |
|
349 |
{ |
|
350 |
MPX_DEBUG1( "CMPXCollectionViewHgPlaylistHelper::HandleOpenL - Opening playlist" ); |
|
351 |
||
352 |
// toggle repeat and shuffle to off if podcast playlist |
|
353 |
if(KMPXUidPodcastDBPlugin == TUid::Uid((TInt)aPlaylist.Path().Id(0))) |
|
354 |
{ |
|
355 |
CMPXCollectionPlaylist* tmp = |
|
356 |
CMPXCollectionPlaylist::NewL( aPlaylist ); |
|
357 |
CleanupStack::PushL( tmp ); |
|
358 |
tmp->SetRepeatEnabled( EFalse ); |
|
359 |
tmp->SetShuffleEnabledL( EFalse ); |
|
360 |
iPlaybackUtility->InitL( *tmp, EFalse ); |
|
361 |
CleanupStack::PopAndDestroy( tmp ); |
|
362 |
} |
|
363 |
else |
|
364 |
{ |
|
365 |
iPlaybackUtility->InitL( aPlaylist, EFalse ); |
|
366 |
} |
|
367 |
} |
|
368 |
else |
|
369 |
{ |
|
370 |
MPX_DEBUG1( "CMPXCollectionViewHgPlaylistHelper::HandleOpenL - Init canceled, do nothing" ); |
|
371 |
} |
|
372 |
} |
|
373 |
else |
|
374 |
{ |
|
375 |
if( iDefaultPath ) |
|
376 |
{ |
|
377 |
// Failed to open default path, set to initialized |
|
378 |
// "No songs view" |
|
379 |
// |
|
380 |
iDefaultPath = EFalse; |
|
381 |
iPathInitialized = ETrue; |
|
382 |
iIsInitializing = EFalse; |
|
383 |
} |
|
384 |
else |
|
385 |
{ |
|
386 |
// Try opening default |
|
387 |
LoadDefaultPathL(); |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
// --------------------------------------------------------------------------- |
|
393 |
// Initialize the playback engine with a collection path |
|
394 |
// --------------------------------------------------------------------------- |
|
395 |
// |
|
396 |
void CMPXCollectionViewHgPlaylistHelper::InitPlaybackEngineL( CMPXCollectionPath& aPath ) |
|
397 |
{ |
|
398 |
MPX_FUNC( "CMPXCollectionViewHgPlaylistHelper::InitPlaybackEngineL" ); |
|
399 |
||
400 |
if( !iInitCanceled ) |
|
401 |
{ |
|
402 |
TTime time; |
|
403 |
time.UniversalTime(); |
|
404 |
TInt64 seed = time.Int64(); |
|
405 |
TInt randIndex = Math::Rand(seed) % aPath.Count(); |
|
406 |
aPath.Set(randIndex); |
|
407 |
CMPXCollectionPlaylist* playlist = CMPXCollectionPlaylist::NewL( aPath ); |
|
408 |
CleanupStack::PushL( playlist ); |
|
409 |
playlist->SetShuffleEnabledL( ETrue ); |
|
410 |
iPlaybackUtility->SetL( EPbPropertyRandomMode, iEnableShuffle ); |
|
411 |
iPlaybackUtility->InitL( *playlist, ETrue ); |
|
412 |
CleanupStack::PopAndDestroy( playlist ); |
|
413 |
} |
|
414 |
else |
|
415 |
{ |
|
416 |
iIsInitializing = EFalse; |
|
417 |
iPathInitialized = ETrue; |
|
418 |
iInitCanceled = EFalse; |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
// ----------------------------------------------------------------------------- |
|
423 |
// Handle playback message |
|
424 |
// ----------------------------------------------------------------------------- |
|
425 |
// |
|
426 |
void CMPXCollectionViewHgPlaylistHelper::DoHandlePlaybackMessageL( const CMPXMessage& aMessage ) |
|
427 |
{ |
|
428 |
MPX_FUNC( "CMPXCollectionViewHgPlaylistHelper::DoHandlePlaybackMessageL" ); |
|
429 |
TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
430 |
if ( KMPXMessageGeneral == id ) |
|
431 |
{ |
|
432 |
TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ); |
|
433 |
MPX_DEBUG2( "CMPXCollectionViewHgPlaylistHelper::DoHandlePlaybackMessageL(%d)", event ); |
|
434 |
||
435 |
switch ( event ) |
|
436 |
{ |
|
437 |
default: |
|
438 |
{ |
|
439 |
// ignore other messages |
|
440 |
break; |
|
441 |
} |
|
442 |
} |
|
443 |
} |
|
444 |
} |
|
445 |
||
446 |
// ----------------------------------------------------------------------------- |
|
447 |
// Handle collection message |
|
448 |
// ----------------------------------------------------------------------------- |
|
449 |
// |
|
450 |
void CMPXCollectionViewHgPlaylistHelper::DoHandleCollectionMessageL( |
|
451 |
const CMPXMessage& /*aMessage*/ ) |
|
452 |
{ |
|
453 |
MPX_FUNC( "CMPXCollectionViewHgPlaylistHelper::DoHandleCollectionMessageL" ); |
|
454 |
||
455 |
} |
|
456 |
||
457 |
// ----------------------------------------------------------------------------- |
|
458 |
// Start the incremental reading operation at an offset |
|
459 |
// ----------------------------------------------------------------------------- |
|
460 |
// |
|
461 |
void CMPXCollectionViewHgPlaylistHelper::DoIncrementalOpenL( CMPXCollectionPath& aPath, |
|
462 |
TInt aIndex, |
|
463 |
TInt aDelay ) |
|
464 |
{ |
|
465 |
RArray<TMPXAttribute> attrs; |
|
466 |
CleanupClosePushL( attrs ); |
|
467 |
TArray<TMPXAttribute> ary = attrs.Array(); |
|
468 |
iIncOpenUtil->Stop(); |
|
469 |
iIncOpenUtil->SetDelay( aDelay ); |
|
470 |
iIncOpenUtil->StartL( aPath, ary, KIncrementalFetchCount, |
|
471 |
aIndex, CMPXCollectionOpenUtility::EFetchNormal ); |
|
472 |
CleanupStack::PopAndDestroy( &attrs ); |
|
473 |
} |
|
474 |
||
475 |
||
476 |
// End of File |