2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "AudioLyricsUtil.h"
19 #include <dpl/singleton_impl.h>
20 #include <metadata_extractor.h>
25 IMPLEMENT_SINGLETON(DeviceAPI::Content::MediaLyricsUtil)
30 metadata_extractor_h m_extractor = NULL;
31 MediaLyricsUtil::MediaLyricsUtil()
33 if ( METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_create(&m_extractor))
35 LoggerD("MetaData Extractor create Fail...");
39 MediaLyricsUtil::~MediaLyricsUtil()
41 if ( m_extractor && METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_destroy(m_extractor))
43 LoggerD("Metadata extractor destory Fail...");
47 MediacontentLyricsPtr MediaLyricsUtil::fetchLyrics(string filepath)
49 MediacontentLyricsPtr result;
50 //MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
55 if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_set_path(m_extractor, filepath.c_str()) )
57 char* strSyncTextNum=NULL;
58 metadata_extractor_attr_e attr = METADATA_SYNCLYRICS_NUM;
59 if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &strSyncTextNum)
63 istringstream(strSyncTextNum) >> nSyncTextNum;
65 strSyncTextNum = NULL;
66 if ( nSyncTextNum > 0)
68 MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
69 lyricsPtr->setMediaLyricsType("SYNCHRONIZED");
70 for(int i=0; i < nSyncTextNum; i++)
72 unsigned long time_info = 0;
74 if ( METADATA_EXTRACTOR_ERROR_NONE ==
75 metadata_extractor_get_synclyrics(m_extractor, i, &time_info, &lyrics))
77 lyricsPtr->addMediaLyricsTimeStamp(time_info);
80 lyricsPtr->addMediaLyricsText(lyrics);
81 //LoggerI( "[" << time_info << "]"<< "lyrics : " << lyrics);
85 lyricsPtr->addMediaLyricsText("");
97 char* unSyncText = NULL;
98 attr = METADATA_UNSYNCLYRICS;
100 if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &unSyncText) )
104 MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
105 lyricsPtr->setMediaLyricsType("UNSYNCHRONIZED");
106 lyricsPtr->addMediaLyricsTimeStamp(0);
107 lyricsPtr->addMediaLyricsText(unSyncText);
121 LoggerD("extractor Error!!!");
129 LoggerD(" extractor is invaild ");