|
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: Music Player stautus observer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mpxplaybackutility.h> |
|
20 #include <mpxplaybackmessage.h> |
|
21 #include <mpxmedia.h> |
|
22 #include <mpxmediageneraldefs.h> |
|
23 #include <mpxmediamusicdefs.h> |
|
24 #include <mpxmessagegeneraldefs.h> |
|
25 #include <mpxplaybackmessagedefs.h> |
|
26 #include <mpxalbumartutil.h> |
|
27 #include <mpxlog.h> |
|
28 |
|
29 #include "aiplayerpluginengine.h" |
|
30 |
|
31 const TInt KMPXOneSecInMilliSecs( 1000 ); |
|
32 const TUid KMusicPlayerAppUid = { 0x102072C3 }; |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CAiPlayerPluginEngine::ConstructL |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void CAiPlayerPluginEngine::ConstructL() |
|
41 { |
|
42 MPX_DEBUG1("CAiPlayerPluginEngine::ConstructL"); |
|
43 // Get the playback utility instance from engine. |
|
44 //iPlaybackUtility = MMPXPlaybackUtility::NewL( KPbModeActivePlayer, this ); |
|
45 iPlaybackUtility = MMPXPlaybackUtility::NewL( KMusicPlayerAppUid, this ); |
|
46 iAlbumArtUtil = CMPXAlbumArtUtil::NewL(); |
|
47 if (iPlaybackUtility->StateL() == EPbStatePlaying) |
|
48 { |
|
49 RequestMediaL(); |
|
50 } |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CAiPlayerPluginEngine::NewL |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CAiPlayerPluginEngine* CAiPlayerPluginEngine::NewL( |
|
58 MAiPlayerPluginEngineObserver& aObserver ) |
|
59 { |
|
60 MPX_DEBUG1("CAiPlayerPluginEngine::NewL"); |
|
61 CAiPlayerPluginEngine* self = new ( ELeave ) |
|
62 CAiPlayerPluginEngine( aObserver ); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CAiPlayerPluginEngine::CAiPlayerPluginEngine |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CAiPlayerPluginEngine::CAiPlayerPluginEngine( |
|
74 MAiPlayerPluginEngineObserver& aObserver ) |
|
75 : iObserver( &aObserver ), |
|
76 iPlaybackUtility( NULL ), |
|
77 iTitle( NULL ), |
|
78 iArtist( NULL ), |
|
79 iUri( NULL ), |
|
80 iMedia( NULL ), |
|
81 iPosition( KErrNotFound ), |
|
82 iDuration( KErrNotFound ), |
|
83 iExtractingAlbumArt( EFalse ), |
|
84 iSkipping( EFalse ) |
|
85 { |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CAiPlayerPluginEngine::~CAiPlayerPluginEngine |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CAiPlayerPluginEngine::~CAiPlayerPluginEngine() |
|
93 { |
|
94 MPX_DEBUG1("CAiPlayerPluginEngine::~CAiPlayerPluginEngine"); |
|
95 if ( iPlaybackUtility ) |
|
96 { |
|
97 iPlaybackUtility->Close(); |
|
98 } |
|
99 delete iMedia; |
|
100 delete iAlbumArtUtil; |
|
101 delete iTitle; |
|
102 delete iArtist; |
|
103 delete iUri; |
|
104 |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // From MMPXPlaybackObserver |
|
109 // Handle playback message. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CAiPlayerPluginEngine::HandlePlaybackMessage( CMPXMessage* aMessage, |
|
113 TInt aError ) |
|
114 { |
|
115 if ( aError == KErrNone && aMessage ) |
|
116 { |
|
117 TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); |
|
118 } |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // From MMPXPlaybackCallback |
|
123 // Handle playback property. |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CAiPlayerPluginEngine::HandlePropertyL( TMPXPlaybackProperty aProperty, |
|
127 TInt aValue, TInt aError ) |
|
128 { |
|
129 DoHandlePropertyL( aProperty, aValue, aError ); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // From MMPXPlaybackCallback |
|
134 // Method is called continously until aComplete=ETrue, signifying that |
|
135 // it is done and there will be no more callbacks |
|
136 // Only new items are passed each time |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CAiPlayerPluginEngine::HandleSubPlayerNamesL( |
|
140 TUid /* aPlayer */, |
|
141 const MDesCArray* /* aSubPlayers */, |
|
142 TBool /* aComplete */, |
|
143 TInt /* aError */ ) |
|
144 { |
|
145 // do nothing |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // From MMPXPlaybackCallback |
|
150 // Handle media |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CAiPlayerPluginEngine::HandleMediaL( const CMPXMedia& aMedia, |
|
154 TInt aError ) |
|
155 { |
|
156 MPX_DEBUG1("CAiPlayerPluginEngine::HandleMediaL"); |
|
157 if ( KErrNone == aError ) |
|
158 { |
|
159 delete iUri; |
|
160 iUri = NULL; |
|
161 if (aMedia.IsSupported(KMPXMediaGeneralUri)) |
|
162 { |
|
163 TParsePtrC filePath(aMedia.ValueText(KMPXMediaGeneralUri) ); |
|
164 iUri = filePath.FullName().AllocL(); |
|
165 } |
|
166 |
|
167 delete iTitle; |
|
168 iTitle = NULL; |
|
169 if ( aMedia.IsSupported( KMPXMediaGeneralTitle ) ) |
|
170 { |
|
171 iTitle = ( aMedia.ValueText( KMPXMediaGeneralTitle ) ).AllocL(); |
|
172 } |
|
173 else if ( aMedia.IsSupported( KMPXMediaGeneralUri ) ) |
|
174 { |
|
175 TParsePtrC filePath( aMedia.ValueText( KMPXMediaGeneralUri ) ); |
|
176 iTitle = (filePath.Name()).AllocL(); |
|
177 } |
|
178 delete iArtist; |
|
179 iArtist = NULL; |
|
180 if ( aMedia.IsSupported( KMPXMediaMusicArtist ) ) |
|
181 { |
|
182 iArtist = ( aMedia.ValueText( KMPXMediaMusicArtist ) ).AllocL(); |
|
183 } |
|
184 |
|
185 iObserver->TrackInfoChanged(iTitle ? *iTitle : KNullDesC(), iArtist ? *iArtist : KNullDesC()); |
|
186 |
|
187 if (!iSkipping) |
|
188 { |
|
189 if (iExtractingAlbumArt) |
|
190 { |
|
191 iAlbumArtUtil->CancelRequest(); |
|
192 iExtractingAlbumArt=EFalse; |
|
193 } |
|
194 |
|
195 if ( aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName ) ) |
|
196 { |
|
197 delete iMedia; |
|
198 iMedia=NULL; |
|
199 iMedia = CMPXMedia::NewL( aMedia ); |
|
200 TRAPD(err,iAlbumArtUtil->ExtractAlbumArtL( |
|
201 *iMedia, |
|
202 *this, |
|
203 TSize(70,70), |
|
204 EFalse)); |
|
205 |
|
206 if (err != KErrNone) |
|
207 { |
|
208 iObserver->AlbumArtChanged(NULL); |
|
209 } |
|
210 } |
|
211 else |
|
212 { |
|
213 iObserver->AlbumArtChanged(NULL); |
|
214 } |
|
215 |
|
216 } |
|
217 else |
|
218 { |
|
219 iObserver->AlbumArtChanged(NULL); |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // From MMPXPlaybackCallback |
|
226 // Handle completion of a asynchronous command |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 void CAiPlayerPluginEngine::HandlePlaybackCommandComplete( |
|
230 CMPXCommand* /*aCommandResult*/, TInt /*aError*/ ) |
|
231 { |
|
232 // do nothing |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // From MMPXAlbumArtUtilObserver |
|
237 // Notify that extraction of album art started. |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void CAiPlayerPluginEngine::ExtractAlbumArtStarted() |
|
241 { |
|
242 iExtractingAlbumArt = ETrue; |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // From MMPXAlbumArtUtilObserver |
|
247 // Notify that the extraction of album art has completed. |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CAiPlayerPluginEngine::ExtractAlbumArtCompleted( |
|
251 CFbsBitmap* aBitmap, |
|
252 TInt aErr ) |
|
253 { |
|
254 if (aErr == KErrNone) |
|
255 { |
|
256 iObserver->AlbumArtChanged(aBitmap); |
|
257 } |
|
258 else |
|
259 { |
|
260 iObserver->AlbumArtChanged(NULL); |
|
261 } |
|
262 iExtractingAlbumArt = EFalse; |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // Get the current state of the active player |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 TMPlayerState CAiPlayerPluginEngine::PlayerState() |
|
270 { |
|
271 MPX_DEBUG1( "CAiPlayerPluginEngine::PlayerState" ); |
|
272 TMPXPlaybackState state( EPbStateNotInitialised ); |
|
273 TRAP_IGNORE( state = iPlaybackUtility->StateL() ); |
|
274 return MapState( state ); |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // CAiPlayerPluginEngine::TitleL |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 const TDesC& CAiPlayerPluginEngine::TitleL() |
|
282 { |
|
283 |
|
284 if ( iTitle ) |
|
285 { |
|
286 return *iTitle; |
|
287 } |
|
288 else |
|
289 { |
|
290 RequestMediaL(); |
|
291 return KNullDesC; |
|
292 } |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // CAiPlayerPluginEngine::Artist |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 const TDesC& CAiPlayerPluginEngine::Artist() |
|
300 { |
|
301 if ( iArtist ) |
|
302 { |
|
303 return *iArtist; |
|
304 } |
|
305 else |
|
306 { |
|
307 return KNullDesC; |
|
308 } |
|
309 } |
|
310 // --------------------------------------------------------------------------- |
|
311 // CAiPlayerPluginEngine::Artist |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 const TDesC& CAiPlayerPluginEngine::Uri() |
|
315 { |
|
316 if ( iUri ) |
|
317 { |
|
318 return *iUri; |
|
319 } |
|
320 else |
|
321 { |
|
322 return KNullDesC; |
|
323 } |
|
324 } |
|
325 |
|
326 // ---------------------------------------------------- |
|
327 // CAiPlayerPluginEngine::Position |
|
328 // ---------------------------------------------------- |
|
329 // |
|
330 TInt CAiPlayerPluginEngine::Position() |
|
331 { |
|
332 return iPosition; |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------- |
|
336 // CAiPlayerPluginEngine::Duration |
|
337 // ---------------------------------------------------- |
|
338 // |
|
339 TInt CAiPlayerPluginEngine::Duration() |
|
340 { |
|
341 return iDuration; |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // Handle playback message. |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 void CAiPlayerPluginEngine::DoHandlePlaybackMessageL( |
|
349 const CMPXMessage& aMessage ) |
|
350 { |
|
351 MPX_DEBUG1("CAiPlayerPluginEngine::DoHandlePlaybackMessageL"); |
|
352 |
|
353 TMPXMessageId id( |
|
354 aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
355 if ( KMPXMessageGeneral == id ) |
|
356 { |
|
357 TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ); |
|
358 MPX_DEBUG2( "CAiPlayerPluginEngine::DoHandlePlaybackMessageL(%d)", |
|
359 event ); |
|
360 switch ( event ) |
|
361 { |
|
362 case TMPXPlaybackMessage::EPropertyChanged: |
|
363 { |
|
364 TInt error( KErrNone ); |
|
365 DoHandlePropertyL( |
|
366 aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ), |
|
367 aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ), |
|
368 error ); |
|
369 break; |
|
370 } |
|
371 case TMPXPlaybackMessage::EStateChanged: |
|
372 { |
|
373 TMPXPlaybackState state( |
|
374 aMessage.ValueTObjectL<TMPXPlaybackState>( |
|
375 KMPXMessageGeneralType )); |
|
376 MPX_DEBUG2("CAiPlayerPluginEngine::HandlePlaybackMessageL - E" |
|
377 "StateChanged(%d)", state); |
|
378 |
|
379 DoHandleStateChangedL( state ); |
|
380 break; |
|
381 } |
|
382 case TMPXPlaybackMessage::EMediaChanged: |
|
383 case TMPXPlaybackMessage::EPlaylistUpdated: |
|
384 { |
|
385 MMPXSource* s = iPlaybackUtility->Source(); |
|
386 if ( s ) |
|
387 { |
|
388 RequestMediaL(); |
|
389 } |
|
390 else |
|
391 { |
|
392 iObserver->PlaylisIsEmpty(); |
|
393 } |
|
394 break; |
|
395 } |
|
396 case TMPXPlaybackMessage::ECommandReceived: |
|
397 { |
|
398 MPX_DEBUG2("CAiPlayerPluginEngine::HandlePlaybackMessageL - E" |
|
399 "CommandReceived(%d)", |
|
400 aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) ); |
|
401 break; |
|
402 } |
|
403 case TMPXPlaybackMessage::EActivePlayerChanged: |
|
404 { |
|
405 MPX_DEBUG3("CAiPlayerPluginEngine::HandlePlaybackMessageL - E" |
|
406 "ActivePlayerChanged(%d, %d)", |
|
407 aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ), |
|
408 aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) ); |
|
409 iPlaybackUtility->PropertyL( *this, EPbPropertyPosition ); |
|
410 iPlaybackUtility->PropertyL( *this, EPbPropertyDuration ); |
|
411 DoHandleStateChangedL( iPlaybackUtility->StateL() ); |
|
412 // refresh media property |
|
413 RequestMediaL(); |
|
414 break; |
|
415 } |
|
416 case TMPXPlaybackMessage::ESkipping: |
|
417 { |
|
418 MPX_DEBUG1( "CAiPlayerPluginEngine::DoHandlePlaybackMessageL - ESkipping"); |
|
419 iAlbumArtUtil->CancelRequest(); |
|
420 iObserver->Opening(); |
|
421 iSkipping =ETrue; |
|
422 break; |
|
423 } |
|
424 case TMPXPlaybackMessage::ESkipEnd: |
|
425 { |
|
426 MPX_DEBUG1( "CAiPlayerPluginEngine::DoHandlePlaybackMessageL - ESkipEnd()"); |
|
427 iSkipping = EFalse; |
|
428 break; |
|
429 } |
|
430 default: |
|
431 { |
|
432 break; |
|
433 } |
|
434 } |
|
435 } |
|
436 } |
|
437 |
|
438 // --------------------------------------------------------------------------- |
|
439 // Handle playback property. |
|
440 // --------------------------------------------------------------------------- |
|
441 // |
|
442 void CAiPlayerPluginEngine::DoHandlePropertyL( TInt aProperty, TInt aValue, |
|
443 TInt aError ) |
|
444 { |
|
445 MPX_DEBUG4("CAiPlayerPluginEngine::DoHandlePropertyL - Property(%d); Valu" |
|
446 "e(%d); Error(%d)", aProperty, aValue, aError ); |
|
447 if ( KErrNone == aError ) |
|
448 { |
|
449 switch ( aProperty ) |
|
450 { |
|
451 case EPbPropertyPosition: |
|
452 { |
|
453 iPosition = aValue / KMPXOneSecInMilliSecs; |
|
454 iObserver->PlaybackPositionChanged( iPosition ); |
|
455 break; |
|
456 } |
|
457 case EPbPropertyDuration: |
|
458 { |
|
459 iDuration = aValue / KMPXOneSecInMilliSecs; |
|
460 break; |
|
461 } |
|
462 default: |
|
463 { |
|
464 break; |
|
465 } |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // Handle playback state changed. |
|
472 // --------------------------------------------------------------------------- |
|
473 // |
|
474 void CAiPlayerPluginEngine::DoHandleStateChangedL( TMPXPlaybackState aState ) |
|
475 { |
|
476 TMPlayerState state = MapState( aState ); |
|
477 MPX_DEBUG3("CAiPlayerPluginEngine::DoHandleStateChangedL - State mapped " |
|
478 "from (%d) to (%d)", aState, state ); |
|
479 if (state != EMPlayerStateStarting) |
|
480 { |
|
481 iObserver->PlayerStateChanged(state); |
|
482 } |
|
483 else |
|
484 { |
|
485 iObserver->Opening(); |
|
486 } |
|
487 } |
|
488 |
|
489 // --------------------------------------------------------------------------- |
|
490 // Displays error notes. |
|
491 // --------------------------------------------------------------------------- |
|
492 // |
|
493 void CAiPlayerPluginEngine::HandleErrorL( TInt aError ) |
|
494 { |
|
495 MPX_DEBUG2("CAiPlayerPluginEngine::HandleErrorL(%d)", aError ); |
|
496 } |
|
497 |
|
498 // --------------------------------------------------------------------------- |
|
499 // Map states from TMPXPlaybackState to TMPlayerState |
|
500 // --------------------------------------------------------------------------- |
|
501 // |
|
502 TMPlayerState CAiPlayerPluginEngine::MapState( TMPXPlaybackState aState ) |
|
503 { |
|
504 TMPlayerState state = EMPlayerStateOther; |
|
505 switch ( aState ) |
|
506 { |
|
507 case EPbStatePlaying: |
|
508 state = EMPlayerStatePlaying; |
|
509 break; |
|
510 case EPbStatePaused: |
|
511 state = EMPlayerStatePaused; |
|
512 break; |
|
513 case EPbStateSeekingForward: |
|
514 case EPbStateSeekingBackward: |
|
515 state = EMPlayerStateSeeking; |
|
516 break; |
|
517 case EPbStateNotInitialised: |
|
518 case EPbStateInitialising: |
|
519 state = EMPlayerStateStarting; |
|
520 break; |
|
521 case EPbStateStopped: |
|
522 state = EMPlayerStateStopped; |
|
523 break; |
|
524 default: |
|
525 break; |
|
526 } |
|
527 return state; |
|
528 } |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // Requests Media. |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 void CAiPlayerPluginEngine::RequestMediaL() |
|
535 { |
|
536 MPX_DEBUG1( "CAiPlayerPluginEngine::RequestMediaL" ); |
|
537 MMPXSource* s = iPlaybackUtility->Source(); |
|
538 if ( s ) |
|
539 { |
|
540 RArray<TMPXAttribute> attrs; |
|
541 CleanupClosePushL(attrs); |
|
542 attrs.Append( KMPXMediaGeneralUri ); |
|
543 attrs.Append( KMPXMediaGeneralTitle ); |
|
544 attrs.Append( KMPXMediaMusicArtist ); |
|
545 attrs.Append( KMPXMediaMusicAlbumArtFileName ); |
|
546 s->MediaL( attrs.Array(), *this ); |
|
547 CleanupStack::PopAndDestroy( &attrs ); |
|
548 } |
|
549 } |
|
550 // End of File |