2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dpl/log/log.h>
18 #include <dpl/scoped_ptr.h>
20 #include "Mediacontent.h"
21 #include "MediacontentManager.h"
22 #include "MediaFilterValidator.h"
23 #include "MediaSearchVisitor.h"
29 using namespace TizenApis::Api::Mediacontent;
30 using namespace WrtDeviceApis::Commons;
34 const string SELECT_FOLDER_QUERY =
35 "select folder_uuid, path, title, storage_type,modified_date from (select folder_uuid, path, folder_name as title, storage_type,modified_date from visual_folder where valid=1 union select folder_uuid, path, folder_name as title, storage_type,modified_date from audio_folder) where 1 ";
37 const string VIEW_MEDIA_QUERY_WITH_FOLDER =
38 "select visual_uuid as media_uuid, folder_uuid, content_type, display_name, path, thumbnail_path,created_date, released_date, modified_date, description,rating, album, artist, last_played_time, played_count,longitude, latitude, width, height, orientation, genre, author, duration,size from \
39 (select visual_uuid,folder_uuid, content_type, display_name, path, thumbnail_path,null as created_date, released_date, modified_date, description,rating, album, artist, last_played_time, null as played_count,longitude, latitude, width, height, orientation,null as genre, null as author, duration,size from visual_media join \
41 (select visual_uuid as meta_uuid, longitude, latitude, description, width, height, datetaken as released_date, orientation,null as album, null as artist, null as last_played_time,null as duration from image_meta \
43 select visual_uuid as meta_uuid, longitude, latitude, description, width, height, datetaken as released_date, null as orientation, album, artist, last_played_time,duration from video_meta)) \
44 on visual_uuid=meta_uuid \
46 select audio_uuid, folder_uuid as folder_uuid, content_type, title as display_name, path, thumbnail_path, added_time, year, modified_date, description, rating, album, artist, last_played_time, played_count, null as longitude, null as latitude, null as width, null as height, null as orientation, genre, author, duration, size from audio_media) where 1 ";
48 const string SELECT_MEDIA_ID_WITH_FOLDER =
49 "select item_id from item_view where folder_uuid=";
50 const string SELECT_EXTRA_AUDIO =
51 "select copyright,bitrate,track_num,size from audio_media where audio_uuid=";
56 namespace Mediacontent{
58 int Mediacontent::db_connnect_count = 0;
59 sqlite3* Mediacontent::hDBCt = NULL;
61 Mediacontent::Mediacontent()
63 LogDebug("entered" + Mediacontent::db_connnect_count);
65 if(Mediacontent::db_connnect_count == 0)
67 if( SQLITE_OK != db_util_open(MEDIA_DB_PATH, &Mediacontent::hDBCt, 0))
72 Mediacontent::db_connnect_count++;
75 Mediacontent::~Mediacontent()
79 Mediacontent::db_connnect_count--;
80 if(Mediacontent::db_connnect_count < 1)
82 ret = db_util_close(Mediacontent::hDBCt);
86 LogDebug("DB disconnection is failed");
90 Mediacontent::hDBCt = NULL;
91 LogDebug("DB connection is ok");
93 Mediacontent::db_connnect_count = 0;
98 tm Mediacontent::toDateTm(time_t date)
102 localtime_r(&date, &tm_date);
108 void Mediacontent::convertToPlatformFolder(folder_s &media_folder, MediacontentFolderPtr& newFolder)
110 if(media_folder.folder_uuid != NULL)
112 newFolder->setFolderUUID(media_folder.folder_uuid);
114 if(media_folder.folder_path != NULL)
116 newFolder->setFolderName(media_folder.folder_name);
118 if(media_folder.folder_name != NULL)
120 newFolder->setFolderPath(media_folder.folder_path);
123 newFolder->setFolderModifiedDate(toDateTm(media_folder.modified_date));
127 if(media_folder.storage_type == 0)
129 storageType = "INTERNAL";
131 else if( media_folder.storage_type == 1)
133 storageType = "EXTERNAL";
137 storageType = "UNKNOWN";
139 newFolder->setFolderStorageType(storageType);
144 string Mediacontent::makeQuerySortMode(SortModeArrayPtr attr)
149 SortModeArray::iterator it = attr->begin();
151 for (;it!=attr->end(); ++it)
153 attriName = (*it)->getAttributeName();
154 //convert to attribue's name
155 MediaSearchVisitor visitor;
156 attriName = visitor.getPlatformAttr(attriName);
157 if (attriName.compare("") != 0)
161 query.append(" ORDER BY ");
166 query.append(attriName);
168 if ((*it)->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER)
170 query.append(" ASC");
174 query.append(" DESC");
185 void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder)
193 string query(SELECT_FOLDER_QUERY);
196 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
199 if(eFolder->getFilterIsSet())
201 FilterPtr filter = eFolder->getFilter();
203 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
205 visitor->setQueryType(MediaSearchVisitor::QUERY_FOLDER);
206 filter->travel(IVisitor);
207 condition = visitor->getResult();
209 query.append(" and ");
210 query.append(condition);
213 catch(const Exception &ex){
214 LogError("Exception: " << ex.DumpToString());
215 eFolder->setResult(false);
219 if(eFolder->getSortModesIsSet())
221 sortMode = makeQuerySortMode(eFolder->getSortModes());
223 query.append(sortMode);
227 if (eFolder->getLimitIsSet())
229 limitOffset.append(" LIMIT ");
230 std::stringstream limitStream;
231 limitStream << eFolder->getLimit();
232 limitOffset.append(limitStream.str());
233 if(eFolder->getOffsetIsSet())
235 limitOffset.append(" OFFSET ");
236 std::stringstream offsetStream;
237 offsetStream << eFolder->getOffset();
238 limitOffset.append(offsetStream.str());
241 query.append(limitOffset);
244 LogDebug("execute condition [" << condition << "]");
245 LogDebug("execute projection [" << projection << "]");
246 LogDebug("execute sortMode [" << sortMode << "]");
247 LogDebug("execute limitOffset [" << limitOffset << "]");
251 sqlite3_stmt* pStmt = NULL;
252 folder_s media_folder;
253 sqlite3_prepare_v2(Mediacontent::hDBCt, (char *)(query.c_str()), strlen((char *)(query.c_str())), &pStmt, NULL);
254 while( sqlite3_step(pStmt) == SQLITE_ROW)
256 media_folder.folder_uuid = (char *)sqlite3_column_text(pStmt, 0);
257 media_folder.folder_path = (char *)sqlite3_column_text(pStmt, 1);
258 media_folder.folder_name = (char *)sqlite3_column_text(pStmt, 2);
259 media_folder.storage_type = sqlite3_column_int(pStmt, 3);
260 media_folder.modified_date = sqlite3_column_int(pStmt, 4);
262 MediacontentFolderPtr newFolder(new MediacontentFolder());
263 convertToPlatformFolder(media_folder, newFolder);
265 eFolder->addFolder(newFolder);
267 sqlite3_finalize(pStmt);
268 eFolder->setResult(true);
271 catch (const Exception &ex)
273 LogError("Exception: " << ex.DumpToString());
274 eFolder->setResult(false);
276 LogDebug("dykim:end");
280 void Mediacontent::OnRequestReceived(const IEventFindMediaPtr &eMedia)
282 LogDebug("OnRequestReceived::IEventFindMediaPtr entered");
289 string query(VIEW_MEDIA_QUERY_WITH_FOLDER);
291 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
295 if(eMedia->getFilterIsSet())
297 FilterPtr filter = eMedia->getFilter();
299 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
301 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
302 filter->travel(IVisitor);
303 condition = visitor->getResult();
304 query.append(" and ");
305 query.append(condition);
308 catch(const Exception &ex){
309 LogError("Exception: " << ex.DumpToString());
310 eMedia->setResult(false);
314 if(eMedia->getSortModesIsSet())
316 sortMode = makeQuerySortMode(eMedia->getSortModes());
318 query.append(sortMode);
320 if (eMedia->getLimitIsSet())
322 limitOffset.append(" LIMIT ");
323 std::stringstream limitStream;
324 limitStream << eMedia->getLimit();
325 limitOffset.append(limitStream.str());
326 if(eMedia->getOffsetIsSet())
328 limitOffset.append(" OFFSET ");
329 std::stringstream offsetStream;
330 offsetStream << eMedia->getOffset();
331 limitOffset.append(offsetStream.str());
334 query.append(limitOffset);
337 LogDebug("execute condition [" << condition << "]");
338 LogDebug("execute projection [" << projection << "]");
339 LogDebug("execute sortMode [" << sortMode << "]");
340 LogDebug("execute limitOffset [" << limitOffset << "]");
346 sqlite3_stmt* pStmt = NULL;
348 ret = sqlite3_prepare_v2(Mediacontent::hDBCt, (char *)(query.c_str()), query.length(), &pStmt, NULL);
350 while( sqlite3_step(pStmt) == SQLITE_ROW)
353 content_type = sqlite3_column_int(pStmt, 2);
355 if(content_type == MEDIA_TYPE_IMAGE)
358 MediacontentImage *newImage(new MediacontentImage());
359 readImageFromDB(pStmt,newImage);
360 eMedia->addMedia(newImage);
362 else if(content_type == MEDIA_TYPE_VIDEO)
364 MediacontentVideo *newVideo(new MediacontentVideo());
365 readVideoFromDB(pStmt,newVideo);
366 eMedia->addMedia(newVideo);
368 else if(content_type == MEDIA_TYPE_AUDIO)
370 MediacontentAudio *newVAudio(new MediacontentAudio());
371 readAudioFromDB(pStmt,newVAudio);
372 eMedia->addMedia(newVAudio);
377 sqlite3_finalize(pStmt);
378 eMedia->setResult(true);
381 catch (const Exception &ex)
383 LogError("Exception: " << ex.DumpToString());
384 eMedia->setResult(false);
388 void Mediacontent::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
390 LogDebug("OnRequestReceived::IEventFindMediaPtr entered");
397 string query(VIEW_MEDIA_QUERY_WITH_FOLDER);
399 if(eBrowse->getFolderIdIsSet())
401 std::stringstream folderStream;
402 folderStream <<" and folder_uuid='" << eBrowse->getFolderID() <<"' ";
403 query.append(folderStream.str());
406 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
409 if(eBrowse->getFilterIsSet())
411 FilterPtr filter = eBrowse->getFilter();
413 // FIXME validator have to be placed at JS binding.
414 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
415 bool success = filter->validate(validator);
418 ThrowMsg(PlatformException, "Invalid attirbutes.");
420 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
422 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
423 filter->travel(IVisitor);
424 condition = visitor->getResult();
425 query.append(" and ");
426 query.append(condition);
429 catch(const Exception &ex){
430 LogError("Exception: " << ex.DumpToString());
431 eBrowse->setResult(false);
435 if(eBrowse->getSortModesIsSet())
437 sortMode = makeQuerySortMode(eBrowse->getSortModes());
439 query.append(sortMode);
441 if (eBrowse->getLimitIsSet())
443 limitOffset.append(" LIMIT ");
444 std::stringstream limitStream;
445 limitStream << eBrowse->getLimit();
446 limitOffset.append(limitStream.str());
447 if(eBrowse->getOffsetIsSet())
449 limitOffset.append(" OFFSET ");
450 std::stringstream offsetStream;
451 offsetStream << eBrowse->getOffset();
452 limitOffset.append(offsetStream.str());
455 query.append(limitOffset);
458 LogDebug("execute condition [" << condition << "]");
459 LogDebug("execute projection [" << projection << "]");
460 LogDebug("execute sortMode [" << sortMode << "]");
461 LogDebug("execute limitOffset [" << limitOffset << "]");
462 LogDebug("execute query [" << query << "]");
467 sqlite3_stmt* pStmt = NULL;
469 ret = sqlite3_prepare_v2(Mediacontent::hDBCt, (char *)(query.c_str()), query.length(), &pStmt, NULL);
470 while( sqlite3_step(pStmt) == SQLITE_ROW)
472 content_type = sqlite3_column_int(pStmt, 2);
474 if(content_type == MEDIA_TYPE_IMAGE)
477 MediacontentImage *newImage(new MediacontentImage());
478 readImageFromDB(pStmt,newImage);
479 eBrowse->addMedia(newImage);
481 else if(content_type == MEDIA_TYPE_VIDEO)
483 MediacontentVideo *newVideo(new MediacontentVideo());
484 readVideoFromDB(pStmt,newVideo);
485 eBrowse->addMedia(newVideo);
487 else if(content_type == MEDIA_TYPE_AUDIO)
489 MediacontentAudio *newVAudio(new MediacontentAudio());
490 readAudioFromDB(pStmt,newVAudio);
491 eBrowse->addMedia(newVAudio);
494 sqlite3_finalize(pStmt);
495 eBrowse->setResult(true);
498 catch (const Exception &ex)
500 LogError("Exception: " << ex.DumpToString());
501 eBrowse->setResult(false);
505 bool Mediacontent::updateMediaToDB(MediacontentMediaPtr mediaPtr)
511 string type = mediaPtr->getMediaType();
513 if(type.compare("IMAGE")==0)
515 MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
519 if(imagePtr->getIsChangedFavorite())
521 query.append("update visual_media set rating=");
522 std::stringstream offsetStream;
523 offsetStream << imagePtr->getFavorite();
524 query.append(offsetStream.str());
525 query.append(" where visual_uuid='");
526 query.append(imagePtr->getMediaUUID());
528 LogDebug("QUERY : " << query);
530 err = sqlite3_exec(Mediacontent::hDBCt, query.c_str(), NULL, NULL, &errMsg);
531 if (SQLITE_OK != err)
535 LogDebug("DB opertations is failed:" << errMsg);
536 sqlite3_free(errMsg);
537 ThrowMsg(PlatformException, "DB opertations is failed");
544 if(type.compare("VIDEO")==0)
546 MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
550 if(videoPtr->getIsChangedFavorite())
552 std::stringstream offsetStream;
553 offsetStream << "update visual_media set rating=" << videoPtr->getFavorite() << " where visual_uuid=" << "'" << videoPtr->getMediaUUID() << "'";
554 query = offsetStream.str();
555 err = sqlite3_exec(Mediacontent::hDBCt, query.c_str(), NULL, NULL, &errMsg);
556 if (SQLITE_OK != err)
560 LogDebug("DB opertations is failed:" << errMsg);
561 sqlite3_free(errMsg);
562 ThrowMsg(PlatformException, "DB opertations is failed");
566 if(videoPtr->isChangedPlayedTime() || videoPtr->isChangedPlayCount())
568 std::stringstream offsetStream;
569 offsetStream << "update video_meta set last_played_time=" << videoPtr->getVideoPlayedTime() << " where visual_uuid=" << "'" << videoPtr->getMediaUUID() << "'";
570 query = offsetStream.str();
571 err = sqlite3_exec(Mediacontent::hDBCt, query.c_str(), NULL, NULL, &errMsg);
572 if (SQLITE_OK != err)
576 LogDebug("DB opertations is failed:" << errMsg);
577 sqlite3_free(errMsg);
578 ThrowMsg(PlatformException, "DB opertations is failed");
585 if(type.compare("AUDIO")==0)
587 MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
591 if(audioPtr->getIsChangedFavorite())
593 std::stringstream offsetStream;
594 offsetStream << "update audio_media set rating=" << audioPtr->getFavorite() << " where audio_uuid=" << "'" << audioPtr->getMediaUUID() << "'";
595 query = offsetStream.str();
596 err = sqlite3_exec(Mediacontent::hDBCt, query.c_str(), NULL, NULL, &errMsg);
597 if (SQLITE_OK != err)
601 LogDebug("DB opertations is failed:" << errMsg);
602 sqlite3_free(errMsg);
603 ThrowMsg(PlatformException, "DB opertations is failed");
608 if(audioPtr->isChangedPlayedTime() || audioPtr->isChangedPlayCount())
610 std::stringstream offsetStream;
611 offsetStream << "update audio_media set last_played_time=" <<audioPtr->getAudioPlayedTime()<< ",played_count="<<audioPtr->getAudioPlayCount()<<" where audio_uuid=" << "'" << audioPtr->getMediaUUID() << "'";
612 query = offsetStream.str();
613 err = sqlite3_exec(Mediacontent::hDBCt, query.c_str(), NULL, NULL, &errMsg);
614 if (SQLITE_OK != err)
618 LogDebug("DB opertations is failed:" << errMsg);
619 sqlite3_free(errMsg);
620 ThrowMsg(PlatformException, "DB opertations is failed");
630 void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
632 LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
635 MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
637 if(updateMediaToDB(mediaPtr))
639 eMedia->setResult(true);
643 eMedia->setResult(false);
646 catch (const Exception &ex)
648 LogError("Exception: " << ex.DumpToString());
649 eMedia->setResult(false);
654 void Mediacontent::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
656 LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
661 MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
662 if (mediaListPtr->empty())
664 ThrowMsg(PlatformException, "Item vector parameter is empty");
667 if(SQLITE_OK != sqlite3_exec(Mediacontent::hDBCt, "BEGIN IMMEDIATE;", NULL, NULL, &ErrMsg))
669 LogError("Error:failed to begin transaction: error=" << ErrMsg);
670 sqlite3_free(ErrMsg);
671 ThrowMsg(PlatformException,"Error:failed to begin transaction\n");
673 sqlite3_free(ErrMsg);
675 for(unsigned int i=0; i<mediaListPtr->size(); i++)
677 if (eItems->checkCancelled())
679 eItems->setCancelAllowed(true);
680 eItems->setResult(true);
681 if (SQLITE_OK != sqlite3_exec(Mediacontent::hDBCt, "ROLLBACK;", NULL, NULL, &ErrMsg))
683 LogError("Error:failed to rollback transaction: error=" << ErrMsg);
684 sqlite3_free(ErrMsg);
685 ThrowMsg(PlatformException,"Error:failed to rollback transaction\n");
687 sqlite3_free(ErrMsg);
690 MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
691 if(!updateMediaToDB(mediaPtr))
693 ThrowMsg(PlatformException, "DB operation is failed");
696 eItems->setResult(true);
697 if (SQLITE_OK != sqlite3_exec(Mediacontent::hDBCt, "COMMIT;", NULL, NULL, &ErrMsg))
699 LogError("Error:failed to end transaction: error=" << ErrMsg);
700 sqlite3_free(ErrMsg);
701 ThrowMsg(PlatformException,"Error:failed to end transaction\n");
703 sqlite3_free(ErrMsg);
705 catch (const Exception &ex)
707 LogError("Exception: " << ex.DumpToString());
708 eItems->setResult(false);
710 eItems->setCancelAllowed(false);
713 void Mediacontent::readImageFromDB(sqlite3_stmt* pStmt, MediacontentImage* newImage)
719 tmp = (char*)sqlite3_column_text(pStmt,0);
721 newImage->setMediaUUID(tmp);
723 newImage->setMediaType("IMAGE");
726 tmp = (char*)sqlite3_column_text(pStmt,3);
728 newImage->setDisplayName(tmp);
730 tmp = (char*)sqlite3_column_text(pStmt,4);
732 newImage->setFilePath(tmp);
734 tmp = (char*)sqlite3_column_text(pStmt,5);
736 newImage->setThumbnailPath(tmp);
738 newImage->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
739 newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
740 newImage->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
742 tmp = (char*)sqlite3_column_text(pStmt,9);
744 newImage->setDescription(tmp);
746 newImage->setFavorite(sqlite3_column_int(pStmt,10));
747 newImage->setImageLatitude(sqlite3_column_double(pStmt,15));
748 newImage->setImageLongitude(sqlite3_column_double(pStmt,16));
749 newImage->setImageWidth(sqlite3_column_int(pStmt,17));
750 newImage->setImageHeight(sqlite3_column_int(pStmt,18));
751 int orientation = (sqlite3_column_int(pStmt,19));
752 string orientationStr;
756 orientationStr = "NORMAL";
759 orientationStr = "FLIP_HORIZONTAL";
762 orientationStr = "ROTATE_180";
765 orientationStr = "FLIP_VERTICAL";
768 orientationStr = "TRANSPOSE";
771 orientationStr = "ROTATE_90";
774 orientationStr = "TRANSVERSE";
777 orientationStr = "ROTATE_270";
780 newImage->setImageOrientation(orientationStr);
781 newImage->setSize(sqlite3_column_double(pStmt,23));
788 void Mediacontent::readVideoFromDB(sqlite3_stmt* pStmt, MediacontentVideo* newVideo)
794 tmp = (char*)sqlite3_column_text(pStmt,0);
796 newVideo->setMediaUUID(tmp);
798 newVideo->setMediaType("VIDEO");
801 tmp = (char*)sqlite3_column_text(pStmt,3);
803 newVideo->setDisplayName(tmp);
805 tmp = (char*)sqlite3_column_text(pStmt,4);
807 newVideo->setFilePath(tmp);
809 tmp = (char*)sqlite3_column_text(pStmt,5);
811 newVideo->setThumbnailPath(tmp);
813 newVideo->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
814 newVideo->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
815 newVideo->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
817 tmp = (char*)sqlite3_column_text(pStmt,9);
819 newVideo->setDescription(tmp);
821 newVideo->setFavorite(sqlite3_column_int(pStmt,10));
823 tmp = (char*)sqlite3_column_text(pStmt,11);
825 newVideo->setVideoAlbum(tmp);
827 tmp = (char*)sqlite3_column_text(pStmt,12);
829 newVideo->setVideoArtist(tmp);
831 newVideo->setVideoPlayedTime(sqlite3_column_int(pStmt,13));
832 newVideo->setVideoPlayCount(sqlite3_column_int(pStmt,14));
834 newVideo->setVideoLongitude(sqlite3_column_double(pStmt,15));
835 newVideo->setVideoLatitude(sqlite3_column_double(pStmt,16));
837 newVideo->setVideoWidth(sqlite3_column_int(pStmt,17));
838 newVideo->setVideoHeight(sqlite3_column_int(pStmt,18));
840 newVideo->setVideoDuration(sqlite3_column_int(pStmt,22));
841 newVideo->setSize(sqlite3_column_double(pStmt,23));
846 void Mediacontent::readAudioFromDB(sqlite3_stmt* pStmt, MediacontentAudio* newAudio)
852 tmp = (char*)sqlite3_column_text(pStmt,0);
854 newAudio->setMediaUUID(tmp);
856 newAudio->setMediaType("AUDIO");
859 tmp = (char*)sqlite3_column_text(pStmt,3);
861 newAudio->setDisplayName(tmp);
863 tmp = (char*)sqlite3_column_text(pStmt,4);
865 newAudio->setFilePath(tmp);
867 tmp = (char*)sqlite3_column_text(pStmt,5);
869 newAudio->setThumbnailPath(tmp);
872 newAudio->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
875 memset(&tm_date,0x00,sizeof(tm_date));
876 tm_date.tm_year = sqlite3_column_int(pStmt,7);
877 newAudio->setReleasedDate(tm_date);
878 newAudio->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
880 tmp = (char*)sqlite3_column_text(pStmt,9);
882 newAudio->setDescription(tmp);
884 newAudio->setFavorite(sqlite3_column_int(pStmt,10));
886 tmp = (char*)sqlite3_column_text(pStmt,11);
888 newAudio->setAudioAlbum(tmp);
890 tmp = (char*)sqlite3_column_text(pStmt,12);
892 newAudio->setAudioArtist(tmp);
894 newAudio->setAudioPlayedTime(sqlite3_column_int(pStmt,13));
895 newAudio->setAudioPlayCount(sqlite3_column_int(pStmt,14));
897 tmp = (char*)sqlite3_column_text(pStmt,20);
899 newAudio->setAudioGenre(tmp);
901 tmp = (char*)sqlite3_column_text(pStmt,21);
903 newAudio->setAudioComposer(tmp);
905 newAudio->setAudioDuration(sqlite3_column_int(pStmt,22));
906 newAudio->setSize(sqlite3_column_double(pStmt,23));
908 string queryExtraAudio(SELECT_EXTRA_AUDIO);
909 queryExtraAudio.append("'");
910 queryExtraAudio.append(newAudio->getMediaUUID());
911 queryExtraAudio.append("'");
912 sqlite3_stmt* pStmt1 = NULL;
913 //"select copyright,bitrate,track_num,size from audio_media where audio_id=";
914 if(sqlite3_prepare_v2(Mediacontent::hDBCt, (char *)(queryExtraAudio.c_str()), strlen((char *)(queryExtraAudio.c_str())), &pStmt1, NULL) == SQLITE_OK)
916 while( sqlite3_step(pStmt1) == SQLITE_ROW)
918 tmp = (char*)sqlite3_column_text(pStmt,0);
920 newAudio->setAudioCopyright(tmp);
921 newAudio->setAudioBitrate(sqlite3_column_int(pStmt,1));
922 newAudio->setAudioTrackNum(sqlite3_column_int(pStmt,2));
923 newAudio->setAudioSize(sqlite3_column_int(pStmt,3));
925 sqlite3_finalize(pStmt1);
928 MMHandleType tag_attrs = 0;
929 LogDebug("AUDIO PATH: " << newAudio->getFilePath());
930 int ret = mm_file_create_tag_attrs(&tag_attrs, newAudio->getFilePath().c_str());
932 char *err_attr_name = NULL;
936 if (ret == MM_ERROR_NONE && tag_attrs)
938 ret = mm_file_get_attrs( tag_attrs,
940 MM_FILE_TAG_UNSYNCLYRICS, &unSyncText, &unSyncLen,
941 MM_FILE_TAG_SYNCLYRICS_NUM, &syncTextNum,
944 if (ret != MM_ERROR_NONE && err_attr_name)
946 MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
949 lyricsPtr->setMediaLyricsType("SYNCHRONIZED");
950 for(int i=0; i < syncTextNum; i++)
952 unsigned long time_info = 0;
953 char * lyrics_info = NULL;
954 mm_file_get_synclyrics_info(tag_attrs,i,&time_info,&lyrics_info);
955 lyricsPtr->addMediaLyricsTimeStamp(time_info);
956 lyricsPtr->addMediaLyricsText(lyrics_info);
957 LogDebug("SYNCHRONIZED: " << lyrics_info);
962 LogDebug("UNSYNCHRONIZED: " << unSyncText);
963 lyricsPtr->setMediaLyricsType("UNSYNCHRONIZED");
964 lyricsPtr->addMediaLyricsTimeStamp(0);
965 lyricsPtr->addMediaLyricsText(unSyncText);
968 newAudio->setAudioLyrics(lyricsPtr);