| 2 |      1 | /*
 | 
|  |      2 | * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
 | 
|  |      3 | *
 | 
|  |      4 | * All rights reserved.
 | 
|  |      5 | * This component and the accompanying materials are made available
 | 
|  |      6 | * under the terms of the License "Eclipse Public License v1.0"
 | 
|  |      7 | * which accompanies this distribution, and is available
 | 
|  |      8 | * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 | 
|  |      9 | *
 | 
|  |     10 | * Initial Contributors:
 | 
|  |     11 | * EmbedDev AB - initial contribution.
 | 
|  |     12 | *
 | 
|  |     13 | * Contributors:
 | 
|  |     14 | *
 | 
|  |     15 | * Description:
 | 
|  |     16 | *
 | 
|  |     17 | */
 | 
|  |     18 | 
 | 
|  |     19 | #include "MetaDataReader.h"
 | 
|  |     20 | #include <utf.h>
 | 
|  |     21 | #include <charconv.h>
 | 
|  |     22 | #include <eikenv.h>
 | 
|  |     23 | #include <mmf\common\mmfMeta.h>
 | 
|  |     24 | #include "debug.h"
 | 
|  |     25 | 
 | 
|  |     26 | const TInt KMaxParseBuffer = 1024;
 | 
|  |     27 | 
 | 
|  |     28 | CMetaDataReader::CMetaDataReader(MMetaDataReaderObserver& aObserver, RFs& aFs) : iObserver(aObserver), iFs(aFs)
 | 
|  |     29 | {
 | 
|  |     30 | 	iShow = NULL;
 | 
|  |     31 | }
 | 
|  |     32 | 
 | 
|  |     33 | CMetaDataReader::~CMetaDataReader()
 | 
|  |     34 | {
 | 
|  |     35 | 	if( iPlayer )
 | 
|  |     36 | 		{
 | 
|  |     37 | 		iPlayer->Close();
 | 
|  |     38 | 		delete iPlayer;
 | 
|  |     39 | 		}
 | 
|  |     40 | 	
 | 
|  |     41 | 	delete iParseNextShowCallBack;
 | 
|  |     42 | 	iShowsToParse.Close();
 | 
|  |     43 | 	delete iCharConverter;
 | 
|  |     44 | }
 | 
|  |     45 | 
 | 
|  |     46 | void CMetaDataReader::ConstructL()
 | 
|  |     47 | {
 | 
|  |     48 | 	DP("MetaDataReader::ConstructL");
 | 
|  |     49 | 	iPlayer = CMdaAudioPlayerUtility::NewL(*this);
 | 
|  |     50 | 
 | 
|  |     51 | 	TCallBack callback(ParseNextShowCallbackL, this);
 | 
|  |     52 | 	iParseNextShowCallBack = new (ELeave)CAsyncCallBack(callback, CActive::EPriorityStandard);
 | 
|  |     53 | 	iCharConverter = CCnvCharacterSetConverter::NewL();
 | 
|  |     54 | 	iCharConverter->PrepareToConvertToOrFromL(KCharacterSetIdentifierIso88591, iFs); 
 | 
|  |     55 | 	iLastConverterCharset = KCharacterSetIdentifierIso88591;
 | 
|  |     56 | }
 | 
|  |     57 | 
 | 
|  |     58 | void CMetaDataReader::SubmitShowL(CShowInfo *aShowInfo)
 | 
|  |     59 | {
 | 
|  |     60 | 	DP("SubmitShow");
 | 
|  |     61 | 	iShowsToParse.Append(aShowInfo);
 | 
|  |     62 | 	
 | 
|  |     63 | 	if (iShow == NULL) {
 | 
|  |     64 | 		ParseNextShowL();
 | 
|  |     65 | 	}
 | 
|  |     66 | }
 | 
|  |     67 | 
 | 
|  |     68 | TInt CMetaDataReader::ParseNextShowCallbackL(TAny* aMetaDataReader)
 | 
|  |     69 | {
 | 
|  |     70 | 	static_cast<CMetaDataReader*>(aMetaDataReader)->ParseNextShowL();
 | 
|  |     71 | 	return KErrNone;
 | 
|  |     72 | }
 | 
|  |     73 | 
 | 
|  |     74 | void CMetaDataReader::ParseNextShowL()
 | 
|  |     75 | 	{
 | 
|  |     76 | 	DP("ParseNextShow");
 | 
|  |     77 | 	iPlayer->Close();
 | 
|  |     78 | 	if (iShowsToParse.Count() == 0) {
 | 
|  |     79 | 		DP("No more shows, stopping");
 | 
|  |     80 | 		iObserver.ReadMetaDataCompleteL();
 | 
|  |     81 | 		return;
 | 
|  |     82 | 	}
 | 
|  |     83 | 	
 | 
|  |     84 | 	iShow = iShowsToParse[0];
 | 
|  |     85 | 	iShowsToParse.Remove(0);	
 | 
|  |     86 | 
 | 
|  |     87 | 	iPlayer->OpenFileL(iShow->FileName());
 | 
|  |     88 | }
 | 
|  |     89 | 
 | 
|  |     90 | void CMetaDataReader::MapcPlayComplete(TInt /*aError*/)
 | 
|  |     91 | {
 | 
|  |     92 | 	
 | 
|  |     93 | }
 | 
|  |     94 | 
 | 
|  |     95 | void CMetaDataReader::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
 | 
|  |     96 | {
 | 
|  |     97 | 	DP1("MapcInitComplete, file=%S", &(iShow->FileName()));
 | 
|  |     98 | 
 | 
|  |     99 | 
 | 
|  |    100 | 	if(aError == KErrNone)
 | 
|  |    101 | 	{
 | 
|  |    102 | 		HBufC* buf = HBufC::New(KMaxParseBuffer);
 | 
|  |    103 | 		TInt numEntries = 0;
 | 
|  |    104 | 		if (buf != NULL && iPlayer->GetNumberOfMetaDataEntries(numEntries) == KErrNone) {
 | 
|  |    105 | 			DP1("%d meta data entries", numEntries);
 | 
|  |    106 | 			iShow->SetPlayTime((aDuration.Int64()/1000000));
 | 
|  |    107 | 			
 | 
|  |    108 | 			for (int i=0;i<numEntries;i++) {
 | 
|  |    109 | 				CMMFMetaDataEntry * entry = NULL;
 | 
|  |    110 | 				TRAPD(error, entry = iPlayer->GetMetaDataEntryL(i));
 | 
|  |    111 | 				
 | 
|  |    112 | 				if (error != KErrNone) {
 | 
|  |    113 | 					continue;
 | 
|  |    114 | 				}
 | 
|  |    115 | 											
 | 
|  |    116 | 				if (entry->Name() == KMMFMetaEntrySongTitle) {
 | 
|  |    117 | 					buf->Des().Copy(entry->Value());
 | 
|  |    118 | 					TRAP_IGNORE(iShow->SetTitleL(*buf));
 | 
|  |    119 | 					DP1("title: %S", &(iShow->Title()));
 | 
|  |    120 | 				} else if (entry->Name() == _L("artist")) {
 | 
|  |    121 | 					if (iShow->Description().Length() > 0) {
 | 
|  |    122 | 						buf->Des().Copy(iShow->Description());
 | 
|  |    123 | 					}
 | 
|  |    124 | 					buf->Des().Append(_L("\n"));
 | 
|  |    125 | 					buf->Des().Append(entry->Value());
 | 
|  |    126 | 					
 | 
|  |    127 | 					TRAP_IGNORE(iShow->SetDescriptionL(*buf));
 | 
|  |    128 | 				} else if (entry->Name() == KMMFMetaEntryAlbum) {
 | 
|  |    129 | 					if (iShow->Description().Length() > 0) {
 | 
|  |    130 | 					buf->Des().Copy(iShow->Description());
 | 
|  |    131 | 					}
 | 
|  |    132 | 					buf->Des().Append(_L("\n"));
 | 
|  |    133 | 					buf->Des().Append(entry->Value());
 | 
|  |    134 | 					
 | 
|  |    135 | 					TRAP_IGNORE(iShow->SetDescriptionL(*buf));
 | 
|  |    136 | 				}	
 | 
|  |    137 | 				else if (entry->Name() == KMMFMetaEntryAlbumTrack) {
 | 
|  |    138 | 					TLex lexer(entry->Value());
 | 
|  |    139 | 					TUint value = 0;
 | 
|  |    140 | 					if(lexer.Val(value) == KErrNone) {
 | 
|  |    141 | 						iShow->SetTrackNo(value);
 | 
|  |    142 | 					}
 | 
|  |    143 | 				}
 | 
|  |    144 | 				
 | 
|  |    145 | 			}
 | 
|  |    146 | 		}
 | 
|  |    147 | 		delete buf;
 | 
|  |    148 | 		buf = NULL;
 | 
|  |    149 | 	}
 | 
|  |    150 | 
 | 
|  |    151 | 	iObserver.ReadMetaData(*iShow);
 | 
|  |    152 | 	iPlayer->Stop();
 | 
|  |    153 | 	iShow = NULL;
 | 
|  |    154 | 	TRAP_IGNORE(ParseNextShowL());
 | 
|  |    155 | }
 | 
|  |    156 | 
 | 
|  |    157 | void CMetaDataReader::SetIgnoreTrackNo(TBool aIgnoreTrackNo)
 | 
|  |    158 | 	{
 | 
|  |    159 | 	iIgnoreTrackNo = aIgnoreTrackNo;
 | 
|  |    160 | 	}
 |