|
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: MPX album utility API |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <MetaDataUtility.h> |
|
20 #include <MetaDataFieldContainer.h> |
|
21 #include <mpxuser.h> |
|
22 #include <mpxmedia.h> |
|
23 #include <mpxmediamusicdefs.h> |
|
24 #include <mpxmediageneraldefs.h> |
|
25 #include <mpxlog.h> |
|
26 |
|
27 #include "mpxalbumartutilobserver.h" |
|
28 #include "mpximageutil.h" |
|
29 #include "mpxalbumartutil.h" |
|
30 #include <thumbnaildata.h> |
|
31 #include <thumbnailobjectsource.h> |
|
32 |
|
33 _LIT( KMPXAlbumMimeType, "audio/mpeg3" ); |
|
34 |
|
35 // ============================== MEMBER FUNCTIONS ============================ |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // Create the playback utility object |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CMPXAlbumArtUtil* CMPXAlbumArtUtil::NewL() |
|
42 { |
|
43 CMPXAlbumArtUtil* self = new(ELeave)CMPXAlbumArtUtil(); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // Destructor |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C CMPXAlbumArtUtil::~CMPXAlbumArtUtil() |
|
56 { |
|
57 if (iArtUtil) |
|
58 { |
|
59 iArtUtil->CancelRequest(); |
|
60 delete iArtUtil; |
|
61 } |
|
62 if(iFilename) |
|
63 { |
|
64 delete iFilename; |
|
65 iFilename = NULL; |
|
66 } |
|
67 delete iThumbnailManager; |
|
68 } |
|
69 |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // Constructor |
|
73 // ---------------------------------------------------------------------------- |
|
74 // |
|
75 CMPXAlbumArtUtil::CMPXAlbumArtUtil() |
|
76 { |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // Constructor |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 void CMPXAlbumArtUtil::ConstructL() |
|
84 { |
|
85 MPX_FUNC("CMPXAlbumArtUtil::ConstructL()"); |
|
86 iThumbnailManager = CThumbnailManager::NewL( *this ); |
|
87 iThumbnailManager->SetFlagsL( CThumbnailManager::EDefaultFlags ); |
|
88 iThumbnailManager->SetQualityPreferenceL( CThumbnailManager::EOptimizeForPerformance ); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // Create the playback utility object |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C void CMPXAlbumArtUtil::ExtractAlbumArtL(const CMPXMedia& aMedia, |
|
96 MMPXAlbumArtUtilObserver& aObs, |
|
97 const TSize& aSize, |
|
98 TBool aLargestFromCache, |
|
99 TDisplayMode aDisplayMode /*= EColor64K*/) |
|
100 { |
|
101 MPX_DEBUG1("CMPXAlbumArtUtil::ExtractAlbumArtL(): Entering"); |
|
102 MPX_DEBUG_THREAD("CMPXAlbumArtUtil::ExtractAlbumArtL()"); |
|
103 if(iFilename) |
|
104 { |
|
105 delete iFilename; |
|
106 iFilename = NULL; |
|
107 } |
|
108 if ( iArtUtil ) |
|
109 { |
|
110 delete iArtUtil; |
|
111 iArtUtil = NULL; |
|
112 } |
|
113 iArtUtil = CMPXImageUtil::NewL(aObs); |
|
114 iDisplayMode = aDisplayMode; |
|
115 iImageSize = aSize; |
|
116 iObserver = &aObs; |
|
117 |
|
118 if (aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName )) |
|
119 { |
|
120 if ( aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ).Length() == 0) |
|
121 { |
|
122 iReqId = 0; |
|
123 User::Leave( KErrNotFound ); |
|
124 } |
|
125 } |
|
126 |
|
127 if ( aMedia.IsSupported( KMPXMediaGeneralUri ) && |
|
128 aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName )) |
|
129 { |
|
130 iFilename = aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ).AllocL(); |
|
131 |
|
132 if ( aLargestFromCache ) |
|
133 { |
|
134 iThumbnailManager->SetThumbnailSizeL(EAudioFullScreenThumbnailSize); |
|
135 } |
|
136 else |
|
137 { |
|
138 iThumbnailManager->SetThumbnailSizeL(aSize); |
|
139 } |
|
140 |
|
141 ExtractThumbnailL(&aMedia); |
|
142 } |
|
143 else |
|
144 { |
|
145 User::Leave( KErrNotFound ); |
|
146 } |
|
147 MPX_DEBUG1("CMPXAlbumArtUtil::ExtractAlbumArtL(): Exiting"); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // Cancel Asynch requests |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 EXPORT_C void CMPXAlbumArtUtil::CancelRequest() |
|
155 { |
|
156 MPX_DEBUG1("CMPXAlbumArtUtil::CancelRequest(): Entering"); |
|
157 if ( iArtUtil ) |
|
158 { |
|
159 iArtUtil->CancelRequest(); |
|
160 delete iArtUtil; |
|
161 iArtUtil = 0; |
|
162 } |
|
163 if ( iThumbnailManager && iReqId > 0 ) |
|
164 { |
|
165 iThumbnailManager->CancelRequest(iReqId); |
|
166 } |
|
167 iReqId = 0; |
|
168 MPX_DEBUG1("CMPXAlbumArtUtil::CancelRequest(): Exiting"); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // Extract binary data from file |
|
173 // ---------------------------------------------------------------------------- |
|
174 // |
|
175 HBufC8* CMPXAlbumArtUtil::ExtractBinaryMetaDataLC(const TDesC& aFilename, |
|
176 TMetaDataFieldId aFieldId) |
|
177 { |
|
178 MPX_DEBUG1("CMPXAlbumArtUtil::ExtractBinaryMetaDataLC(): Entering"); |
|
179 HBufC8* ret(NULL); |
|
180 |
|
181 if (EUnknownMetaDataField != aFieldId) |
|
182 { |
|
183 CMetaDataUtility* metaDataUtil = CMetaDataUtility::NewL(); |
|
184 CleanupStack::PushL( metaDataUtil ); |
|
185 |
|
186 RArray<TMetaDataFieldId> wantedFields; |
|
187 CleanupClosePushL(wantedFields); |
|
188 wantedFields.AppendL(aFieldId); |
|
189 |
|
190 metaDataUtil->OpenFileL(aFilename, wantedFields); |
|
191 const CMetaDataFieldContainer& metaCont = |
|
192 metaDataUtil->MetaDataFieldsL(); |
|
193 TPtrC data = metaCont.Field( aFieldId ); |
|
194 if(data.Length()==0) |
|
195 { |
|
196 User::Leave( KErrNotFound ); |
|
197 } |
|
198 ret = MPXUser::Alloc8L(data); |
|
199 |
|
200 CleanupStack::PopAndDestroy(&wantedFields); |
|
201 CleanupStack::PopAndDestroy(metaDataUtil); |
|
202 CleanupStack::PushL( ret ); |
|
203 } |
|
204 else |
|
205 { |
|
206 ret = HBufC8::NewLC(0); |
|
207 } |
|
208 |
|
209 MPX_DEBUG1("CMPXAlbumArtUtil::ExtractBinaryMetaDataLC(): Exiting"); |
|
210 return ret; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // Preview thumbnail generation or loading is complete. |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CMPXAlbumArtUtil::ThumbnailPreviewReady( |
|
218 MThumbnailData& /*aThumbnail*/, |
|
219 TThumbnailRequestId /*aId*/ ) |
|
220 { |
|
221 MPX_FUNC( "CMPXAlbumArtUtil::ThumbnailPreviewReady" ); |
|
222 // Not used |
|
223 } |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // Final thumbnail bitmap generation or loading is complete. |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CMPXAlbumArtUtil::ThumbnailReady( |
|
231 TInt aError, MThumbnailData& aThumbnail, |
|
232 TThumbnailRequestId aId ) |
|
233 { |
|
234 MPX_DEBUG2( "CMPXAlbumArtUtil::ThumbnailReady error = %d", aError); |
|
235 |
|
236 if (aError == KErrNone) |
|
237 { |
|
238 CFbsBitmap* tempBitmap; |
|
239 tempBitmap = aThumbnail.DetachBitmap(); |
|
240 if (tempBitmap) |
|
241 { |
|
242 if(iReqId == aId) |
|
243 { |
|
244 iObserver->ExtractAlbumArtCompleted( tempBitmap, KErrNone ); |
|
245 } |
|
246 else |
|
247 { |
|
248 delete tempBitmap; |
|
249 } |
|
250 } |
|
251 else if(iReqId == aId) |
|
252 { |
|
253 iObserver->ExtractAlbumArtCompleted( NULL, KErrNotFound ); |
|
254 } |
|
255 } |
|
256 else if (iArtUtil && iFilename) |
|
257 { |
|
258 TRAPD( err, |
|
259 HBufC8* art( ExtractBinaryMetaDataLC(iFilename->Des(),EMetaDataJpeg )); |
|
260 CleanupStack::Pop(art); |
|
261 iArtUtil->StartToDecodeL(iImageSize, art, iDisplayMode) ); |
|
262 |
|
263 if (err != KErrNone) |
|
264 { |
|
265 iObserver->ExtractAlbumArtCompleted( NULL, KErrNotFound ); |
|
266 } |
|
267 } |
|
268 |
|
269 iReqId = 0; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // Extract Thumbnail for the current song |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CMPXAlbumArtUtil::ExtractThumbnailL( |
|
277 const CMPXMedia* aMedia) |
|
278 { |
|
279 MPX_FUNC("CMPXAlbumArtUtil::ExtractThumbnailL"); |
|
280 |
|
281 TMPXItemId currentId( aMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ); |
|
282 if (currentId == KMPXInvalidItemId ) |
|
283 { |
|
284 User::Leave( KErrNotFound ); |
|
285 } |
|
286 if (aMedia->IsSupported( KMPXMediaMusicAlbumArtFileName ) ) |
|
287 { |
|
288 const TDesC& album = aMedia->ValueText( KMPXMediaMusicAlbumArtFileName ); |
|
289 #ifdef _DEBUG |
|
290 RDebug::RawPrint(album); |
|
291 #endif |
|
292 if (album.Compare( KNullDesC) != 0 ) |
|
293 { |
|
294 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( album, KMPXAlbumMimeType ); |
|
295 TInt ret = NULL; |
|
296 if(iThumbnailManager && iReqId >0) |
|
297 { |
|
298 iThumbnailManager->CancelRequest( iReqId ); |
|
299 } |
|
300 if(iThumbnailManager) |
|
301 { |
|
302 TRAPD(err, iReqId = TInt (iThumbnailManager->GetThumbnailL( *source, (TAny*)ret))); |
|
303 if( err != KErrNone) |
|
304 { |
|
305 User::Leave( KErrNotFound ); |
|
306 } |
|
307 } |
|
308 CleanupStack::PopAndDestroy( source ); |
|
309 } |
|
310 } |
|
311 } |
|
312 |