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()
34 if ( METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_create(&m_extractor))
36 LoggerD("MetaData Extractor create Fail...");
40 MediaLyricsUtil::~MediaLyricsUtil()
43 if ( m_extractor && METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_destroy(m_extractor))
45 LoggerD("Metadata extractor destory Fail...");
49 MediacontentLyricsPtr MediaLyricsUtil::fetchLyrics(string filepath)
51 MediacontentLyricsPtr result;
52 //MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
57 LoggerD("Valide Extractor");
60 LoggerD("set Path : " << filepath);
62 if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_set_path(m_extractor, filepath.c_str()) )
64 char* strSyncTextNum=NULL;
65 metadata_extractor_attr_e attr = METADATA_SYNCLYRICS_NUM;
66 if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &strSyncTextNum)
69 LoggerD("SYNCHRONIZED");
71 istringstream(strSyncTextNum) >> nSyncTextNum;
72 LoggerD("nSyncTextNum : " << nSyncTextNum);
75 strSyncTextNum = NULL;
77 if ( nSyncTextNum > 0)
80 MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
81 lyricsPtr->setMediaLyricsType("SYNCHRONIZED");
82 for(int i=0; i < nSyncTextNum; i++)
84 unsigned long time_info = 0;
86 if ( METADATA_EXTRACTOR_ERROR_NONE ==
87 metadata_extractor_get_synclyrics(m_extractor, i, &time_info, &lyrics))
89 lyricsPtr->addMediaLyricsTimeStamp(time_info);
90 lyricsPtr->addMediaLyricsText(lyrics);
91 LoggerD( "timestamp " << time_info << "lyrics : " << lyrics);
99 LoggerD("sync Lyrics Error. text num is 0");
101 char* unSyncText = NULL;
102 attr = METADATA_UNSYNCLYRICS;
104 if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &unSyncText) )
108 MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
109 LoggerD("UNSYNCHRONIZED: " << unSyncText);
110 lyricsPtr->setMediaLyricsType("UNSYNCHRONIZED");
111 lyricsPtr->addMediaLyricsTimeStamp(0);
112 lyricsPtr->addMediaLyricsText(unSyncText);
126 LoggerD("extractor Error!!!");
134 LoggerD(" extractor is invaild ");