upload tizen1.0 source
[framework/multimedia/libmedia-service.git] / test / audio / audio_svc_test.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <audio-svc.h>
23 #include <media-svc.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <dirent.h>
28
29 void insert_into_db(MediaSvcHandle * db_handle, const char * dir_path);
30 void msg_print(int line, char *msg);
31
32 int main()
33 {
34         int ret = AUDIO_SVC_ERROR_NONE;
35         char * audio_id = NULL;
36         int size = 0;
37         int idx=0, j;
38         int rows = -1;
39         AudioHandleType *tracks = NULL;
40         AudioHandleType *item = NULL;
41         AudioHandleType  *groups = NULL;
42         MediaSvcHandle * db_handle = NULL;
43         
44         //db open ==================================================
45         ret = media_svc_connect(&db_handle);
46         if (ret != AUDIO_SVC_ERROR_NONE) {
47                 msg_print(__LINE__, "error to open music database");
48                 return -1;
49         }
50 #if 0
51         //create table test ==================================================
52         ret = audio_svc_create_table();
53         if (ret != AUDIO_SVC_ERROR_NONE) {
54                 msg_print(__LINE__, "error to create table");
55                 return -1;
56         }
57 #endif
58 #if 0
59         //insert music files to db ==================================================
60         ret = audio_svc_delete_all(AUDIO_SVC_STORAGE_PHONE);
61         if (ret != AUDIO_SVC_ERROR_NONE) {
62                 msg_print(__LINE__, "error to delete all items on phone");
63                 return -1;
64         }
65         //insert_into_db(db_handle, "/opt/media/Sounds/Music");
66 #endif
67         //iterate all tracks and get the info of tracks ==================================================
68         msg_print(__LINE__, "iterate all tracks");
69         ret = audio_svc_count_list_item(db_handle, AUDIO_SVC_TRACK_ALL, "", "", "", "", &rows);
70         if (ret != AUDIO_SVC_ERROR_NONE) {
71                 msg_print(__LINE__, "error to delete all items on phone");
72                 return -1;
73         }
74
75         if(rows < 1) {
76                 msg_print(__LINE__, "there is no item");
77                 return -1;
78         }
79         else
80                 fprintf(stderr, "rows = [%d]\n", rows);
81         
82         ret = audio_svc_list_item_new(&tracks, rows);
83         if (ret != AUDIO_SVC_ERROR_NONE) {
84                 msg_print(__LINE__, "error to alloc memory for list item");
85                 return -1;
86         }
87         
88         ret = audio_svc_get_list_item(db_handle, AUDIO_SVC_TRACK_ALL, //item_type,
89                 NULL, //type_string,
90                 NULL, //type_string2,
91                 NULL, //filter_string,
92                 NULL, //filter_string2,
93                 0, //offset,
94                 rows, //rows,
95                 tracks
96                 );
97         if (ret != AUDIO_SVC_ERROR_NONE) {
98                 msg_print(__LINE__, "error to get list item");
99                 return -1;
100         }
101         
102         ret = audio_svc_item_new(&item);
103         for (idx = 0; idx < rows; idx++)
104         {
105                 ret = audio_svc_list_item_get_val(tracks, idx, AUDIO_SVC_LIST_ITEM_AUDIO_ID, &audio_id, &size, -1);
106                 if (ret != AUDIO_SVC_ERROR_NONE) {
107                         msg_print(__LINE__, "error audio_svc_list_item_get_val");
108                         return -1;
109                 }
110                 fprintf(stderr, "[audio_id] = %s \n", audio_id);
111                 ret = audio_svc_get_item_by_audio_id(db_handle, audio_id, item);
112                 if (ret != AUDIO_SVC_ERROR_NONE) {
113                         msg_print(__LINE__, "error to get item by audio_id");
114                         return -1;
115                 }
116                 
117                 {
118                         char *audio_id = NULL, *path = NULL, *title = NULL, *album = NULL, *artist = NULL, *thumbname = NULL, *year = NULL;
119                         char thumb_path[AUDIO_SVC_PATHNAME_SIZE] = {0};
120                         int size = -1;
121                         ret = audio_svc_item_get_val(item,
122                                 AUDIO_SVC_TRACK_DATA_AUDIO_ID, &audio_id, &size,
123                                 AUDIO_SVC_TRACK_DATA_PATHNAME, &path, &size,
124                                 AUDIO_SVC_TRACK_DATA_TITLE, &title, &size,
125                                 AUDIO_SVC_TRACK_DATA_ALBUM, &album, &size,
126                                 AUDIO_SVC_TRACK_DATA_ARTIST, &artist, &size,
127                                 AUDIO_SVC_TRACK_DATA_THUMBNAIL_PATH, &thumbname, &size,
128                                 AUDIO_SVC_TRACK_DATA_YEAR, &year, &size,
129                                 -1);
130                         if (ret != AUDIO_SVC_ERROR_NONE) {
131                                 msg_print(__LINE__, "error audio_svc_item_get_val");
132                                 return -1;
133                         }
134                         fprintf(stderr, "**** ITEM INFO[%d] ****\n", idx);
135                         fprintf(stderr, "       **audio_id = %s\n", audio_id);
136                         fprintf(stderr, "       **path = %s\n", path);
137                         fprintf(stderr, "       **title = %s\n", title);
138                         fprintf(stderr, "       **album = %s\n", album);
139                         fprintf(stderr, "       **artist = %s\n", artist);
140                         fprintf(stderr, "       **thumb = %s\n", thumbname);
141                         fprintf(stderr, "       **album = %s\n", album);
142                         fprintf(stderr, "       **year = %s\n", year);
143                         
144
145                         ret = audio_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path, AUDIO_SVC_PATHNAME_SIZE);
146                         if (ret != AUDIO_SVC_ERROR_NONE) {
147                                 msg_print(__LINE__, "error audio_svc_item_get_val");
148                                 return -1;
149                         }
150                         fprintf(stderr, "       **thumb_path = %s\n\n", thumb_path);
151                 }
152
153         }
154         
155         ret = audio_svc_item_free(item);
156         if (ret != AUDIO_SVC_ERROR_NONE) {
157                 msg_print(__LINE__, "error audio_svc_item_free");
158                 return -1;
159         }
160         ret = audio_svc_list_item_free(tracks);
161         if (ret != AUDIO_SVC_ERROR_NONE) {
162                 msg_print(__LINE__, "error audio_svc_list_item_free");
163                 return -1;
164         }
165
166 #if 0
167         ret = audio_svc_update_item_metadata(audio_id, 
168                         AUDIO_SVC_TRACK_DATA_PLAYED_COUNT, 5,
169                         AUDIO_SVC_TRACK_DATA_PLAYED_TIME, 5,
170                         AUDIO_SVC_TRACK_DATA_ADDED_TIME, 5,
171                         AUDIO_SVC_TRACK_DATA_RATING,     AUDIO_SVC_RATING_5,
172                         AUDIO_SVC_TRACK_DATA_TITLE, "Test title", strlen("Test title"),
173                         AUDIO_SVC_TRACK_DATA_ARTIST, NULL, 0,
174                         AUDIO_SVC_TRACK_DATA_ALBUM, "Test album", strlen("Test album"),
175                         AUDIO_SVC_TRACK_DATA_GENRE, "Test genre", strlen("Test genre"),
176                         AUDIO_SVC_TRACK_DATA_AUTHOR, "Test author", strlen("Test author"),
177                         AUDIO_SVC_TRACK_DATA_DESCRIPTION, "Test description", strlen("Test description"),
178                         AUDIO_SVC_TRACK_DATA_YEAR, 2011,
179                         AUDIO_SVC_TRACK_DATA_TRACK_NUM, 10,
180                         AUDIO_SVC_TRACK_DATA_ALBUM_RATING, AUDIO_SVC_RATING_5,
181                         -1);
182         if (ret != AUDIO_SVC_ERROR_NONE) {
183                 msg_print(__LINE__, "error audio_svc_update_item_metadata");
184                 return -1;
185         }
186 #endif
187         //iterate all albums and its tracks ==================================================
188         msg_print(__LINE__, "iterate all albums and its tracks");
189
190         ret = audio_svc_count_group_item(db_handle, AUDIO_SVC_GROUP_BY_ALBUM, NULL, NULL, NULL, NULL, &rows);
191         if (ret != AUDIO_SVC_ERROR_NONE) {
192                 msg_print(__LINE__, "error audio_svc_count_group_item");
193                 return -1;
194         }
195         if(rows < 1) {
196                 msg_print(__LINE__, "there is no group item");
197                 return -1;
198         }
199         else
200                 fprintf(stderr, "rows = [%d]\n", rows);
201         
202         ret = audio_svc_group_item_new(&groups, rows);
203         if (ret != AUDIO_SVC_ERROR_NONE) {
204                 msg_print(__LINE__, "error audio_svc_list_item_new");
205                 return -1;
206         }
207         
208         ret = audio_svc_get_group_item(db_handle, AUDIO_SVC_GROUP_BY_ALBUM, //group_type,
209                 NULL, //limit_string1,
210                 NULL, //limit_string2,
211                 NULL, //filter_string,
212                 NULL, //filter_string2,
213                 0, //offset,
214                 rows, //rows,
215                 groups);
216
217         if (ret != AUDIO_SVC_ERROR_NONE) {
218                 msg_print(__LINE__, "error audio_svc_get_group_item");
219                 return -1;
220         }
221         
222         for (idx = 0; idx < rows; idx++) {
223                 char *main_info = NULL, *sub_info = NULL, *thumbname = NULL;
224                 int album_rating = 0;
225                 int size = 0;
226                 int count = 0;
227                 
228                 ret = audio_svc_group_item_get_val(groups, idx , 
229                         AUDIO_SVC_GROUP_ITEM_THUMBNAIL_PATH, &thumbname, &size,
230                         AUDIO_SVC_GROUP_ITEM_MAIN_INFO, &main_info, &size,
231                         AUDIO_SVC_GROUP_ITEM_SUB_INFO, &sub_info, &size,
232                         AUDIO_SVC_GROUP_ITEM_RATING, &album_rating,
233                         -1);
234
235                 if (ret != AUDIO_SVC_ERROR_NONE) {
236                         msg_print(__LINE__, "error audio_svc_group_item_get_val");
237                         return -1;
238                 }
239                 
240                 fprintf(stderr, "**** GROUP INFO[%d] ****\n", idx);
241                 fprintf(stderr, "       **main_info = %s\n", main_info);
242                 fprintf(stderr, "       **sub_info = %s\n", sub_info);
243                 fprintf(stderr, "       **thumbname = %s\n", thumbname);
244                 fprintf(stderr, "       **album_rating = %d\n\n", album_rating);
245                 
246                 //iterate tracks of albums ==================================================
247                 ret = audio_svc_count_list_item(db_handle, AUDIO_SVC_TRACK_BY_ALBUM, main_info, "", "", "", &count);
248                 if (ret != AUDIO_SVC_ERROR_NONE) {
249                         msg_print(__LINE__, "error audio_svc_count_list_item");
250                         return -1;
251                 }
252                 if(count < 1) {
253                         msg_print(__LINE__, "there is no item");
254                         return -1;
255                 }
256                 else
257                         fprintf(stderr, "       rows = [%d]\n", count);
258
259                 ret = audio_svc_list_item_new(&tracks, count);
260                 if (ret != AUDIO_SVC_ERROR_NONE) {
261                         msg_print(__LINE__, "error audio_svc_list_item_new");
262                         return -1;
263                 }
264
265                 ret = audio_svc_get_list_item(db_handle, AUDIO_SVC_TRACK_BY_ALBUM, main_info, NULL, NULL, NULL, 0, count, tracks);
266                 if (ret != AUDIO_SVC_ERROR_NONE) {
267                         msg_print(__LINE__, "error audio_svc_list_item_new");
268                         ret = audio_svc_group_item_free(groups);
269                         if (ret != AUDIO_SVC_ERROR_NONE) {
270                                 msg_print(__LINE__, "error audio_svc_list_item_free");
271                                 return -1;
272                         }
273                         return -1;
274                 }
275                 
276                 for (j = 0; j < count; j++)
277                 {
278                         char *audio_id = NULL, *title = NULL, *artist = NULL, *thumbname = NULL, *pathname = NULL, *album = NULL;
279                         int rating = 0;
280                         int duration = 0;
281                         int size = 0;
282                                                 
283                         ret = audio_svc_list_item_get_val(tracks, j , 
284                                 AUDIO_SVC_LIST_ITEM_AUDIO_ID, &audio_id, &size,
285                                 AUDIO_SVC_LIST_ITEM_THUMBNAIL_PATH, &thumbname, &size,
286                                 AUDIO_SVC_LIST_ITEM_TITLE, &title, &size,
287                                 AUDIO_SVC_LIST_ITEM_ARTIST, &artist, &size,
288                                 AUDIO_SVC_LIST_ITEM_ALBUM, &album, &size,
289                                 AUDIO_SVC_LIST_ITEM_PATHNAME, &pathname, &size,
290                                 AUDIO_SVC_LIST_ITEM_DURATION, &duration,
291                                 AUDIO_SVC_LIST_ITEM_RATING, &rating,
292                                 -1);
293                         if (ret != AUDIO_SVC_ERROR_NONE) {
294                                 msg_print(__LINE__, "error audio_svc_list_item_get_val");
295                                 ret = audio_svc_list_item_free(tracks);
296                                 if (ret != AUDIO_SVC_ERROR_NONE) {
297                                         msg_print(__LINE__, "error audio_svc_list_item_free");
298                                         return -1;
299                                 }
300                                 return -1;
301                         }
302
303                         fprintf(stderr, "       **audio_id = %s\n", audio_id);
304                         fprintf(stderr, "       **thumbnail_path = %s\n", thumbname);
305                         fprintf(stderr, "       **title = %s\n", title);
306                         fprintf(stderr, "       **artist = %s\n", artist);
307                         fprintf(stderr, "       **album = %s\n", album);
308                         fprintf(stderr, "       **path = %s\n", pathname);
309                         fprintf(stderr, "       **duration = %d\n", duration);
310                         fprintf(stderr, "       **rating = %d\n\n", rating);
311                 }
312                 
313                 ret = audio_svc_list_item_free(tracks);
314                 if (ret != AUDIO_SVC_ERROR_NONE) {
315                         msg_print(__LINE__, "error audio_svc_list_item_free");
316                         return -1;
317                 }
318
319         }
320         
321         ret = audio_svc_group_item_free(groups);
322         if (ret != AUDIO_SVC_ERROR_NONE) {
323                 msg_print(__LINE__, "error audio_svc_list_item_free");
324                 return -1;
325         }
326
327
328         //iterate all Folder and its tracks ==================================================
329         msg_print(__LINE__, "iterate all Folder and its tracks");
330         //AudioHandleType  *groups = NULL;
331         ret = audio_svc_count_group_item(db_handle, AUDIO_SVC_GROUP_BY_FOLDER, NULL, NULL, NULL, NULL, &rows);
332         if (ret != AUDIO_SVC_ERROR_NONE) {
333                 msg_print(__LINE__, "error audio_svc_count_group_item");
334                 return -1;
335         }
336         if(rows < 1) {
337                 msg_print(__LINE__, "there is no group item");
338                 return -1;
339         }
340         else
341                 fprintf(stderr, "rows = [%d]\n", rows);
342         
343         ret = audio_svc_group_item_new(&groups, rows);
344         if (ret != AUDIO_SVC_ERROR_NONE) {
345                 msg_print(__LINE__, "error audio_svc_group_item_new");
346                 return -1;
347         }
348         
349         ret = audio_svc_get_group_item(db_handle, AUDIO_SVC_GROUP_BY_FOLDER, //group_type,
350                 NULL, //limit_string1,
351                 NULL, //limit_string2,
352                 NULL, //filter_string,
353                 NULL, //filter_string2,
354                 0, //offset,
355                 rows, //rows,
356                 groups);
357         if (ret != AUDIO_SVC_ERROR_NONE) {
358                         msg_print(__LINE__, "error audio_svc_get_group_item of get folder");
359                         ret = audio_svc_list_item_free(tracks);
360                         if (ret != AUDIO_SVC_ERROR_NONE) {
361                                 msg_print(__LINE__, "error audio_svc_list_item_free");
362                                 return -1;
363                         }
364                         return -1;
365         }
366         
367         for (idx = 0; idx < rows; idx++) {
368                 char *main_info = NULL, *sub_info = NULL, *thumbname = NULL;
369                 int rating = 0;
370                 int size = 0;
371                 int count = 0;
372
373                 ret = audio_svc_group_item_get_val(groups, idx , 
374                         AUDIO_SVC_GROUP_ITEM_THUMBNAIL_PATH, &thumbname, &size,
375                         AUDIO_SVC_GROUP_ITEM_MAIN_INFO, &main_info, &size,
376                         AUDIO_SVC_GROUP_ITEM_SUB_INFO, &sub_info, &size,
377                         AUDIO_SVC_GROUP_ITEM_RATING, &rating,
378                         -1);
379
380                 if (ret != AUDIO_SVC_ERROR_NONE) {
381                         msg_print(__LINE__, "error audio_svc_list_item_get_val of get folder");
382                         ret = audio_svc_list_item_free(tracks);
383                         if (ret != AUDIO_SVC_ERROR_NONE) {
384                                 msg_print(__LINE__, "error audio_svc_list_item_free");
385                                 return -1;
386                         }
387                         return -1;
388                 }
389                 
390                 fprintf(stderr, "**** FOLDER INFO[%d] ****\n", idx);
391                 fprintf(stderr, "       **main_info = %s\n", main_info);
392                 fprintf(stderr, "       **sub_info = %s\n", sub_info);
393                 fprintf(stderr, "       **thumbname = %s\n", thumbname);
394                 fprintf(stderr, "       **rating = %d\n\n", rating);
395                 
396                 //iterate tracks of albums ==================================================
397                 ret = audio_svc_count_list_item(db_handle, AUDIO_SVC_TRACK_BY_FOLDER, sub_info, "", "", "", &count);
398                 if (ret != AUDIO_SVC_ERROR_NONE) {
399                         msg_print(__LINE__, "error audio_svc_count_list_item");
400                         return -1;
401                 }
402                 if(count < 1) {
403                         msg_print(__LINE__, "there is no item");
404                         return -1;
405                 }
406                 else
407                         fprintf(stderr, "       rows = [%d]\n\n", count);
408
409                 ret = audio_svc_list_item_new(&tracks, count);
410                 if (ret != AUDIO_SVC_ERROR_NONE) {
411                         msg_print(__LINE__, "error audio_svc_list_item_new");
412                         return -1;
413                 }
414
415                 ret = audio_svc_get_list_item(db_handle, AUDIO_SVC_TRACK_BY_FOLDER, sub_info, NULL, NULL, NULL, 0, count, tracks);
416                 if (ret != AUDIO_SVC_ERROR_NONE) {
417                         msg_print(__LINE__, "error audio_svc_list_item_new");
418                         return -1;
419                 }
420                 
421                 for (j = 0; j < count; j++)
422                 {
423                         char *audio_id = NULL, *title = NULL, *artist = NULL, *thumbname = NULL, *pathname = NULL;
424                         int rating = 0;
425                         int duration = 0;
426                         int size = 0;
427                                                 
428                         ret = audio_svc_list_item_get_val(tracks, j , 
429                                 AUDIO_SVC_LIST_ITEM_AUDIO_ID, &audio_id, &size,
430                                 AUDIO_SVC_LIST_ITEM_THUMBNAIL_PATH, &thumbname, &size,
431                                 AUDIO_SVC_LIST_ITEM_TITLE, &title, &size,
432                                 AUDIO_SVC_LIST_ITEM_ARTIST, &artist, &size,
433                                 AUDIO_SVC_LIST_ITEM_PATHNAME, &pathname, &size,
434                                 AUDIO_SVC_LIST_ITEM_DURATION, &duration,
435                                 AUDIO_SVC_LIST_ITEM_RATING, &rating,
436                                 -1);
437                         if (ret != AUDIO_SVC_ERROR_NONE) {
438                                 msg_print(__LINE__, "error audio_svc_list_item_get_val");
439                                 ret = audio_svc_list_item_free(tracks);
440                                 if (ret != AUDIO_SVC_ERROR_NONE) {
441                                         msg_print(__LINE__, "error audio_svc_list_item_free");
442                                         return -1;
443                                 }
444                                 return -1;
445                         }
446
447                         fprintf(stderr, "       **audio_id = %s\n", audio_id);
448                         fprintf(stderr, "       **thumbnail_path = %s\n", thumbname);
449                         fprintf(stderr, "       **title = %s\n", title);
450                         fprintf(stderr, "       **artist = %s\n", artist);
451                         fprintf(stderr, "       **path = %s\n", pathname);
452                         fprintf(stderr, "       **duration = %d\n", duration);
453                         fprintf(stderr, "       **rating = %d\n\n", rating);
454                 }
455                 
456                 ret = audio_svc_list_item_free(tracks);
457                 if (ret != AUDIO_SVC_ERROR_NONE) {
458                         msg_print(__LINE__, "error audio_svc_list_item_free");
459                         return -1;
460                 }
461
462         }
463         
464         ret = audio_svc_group_item_free(groups);
465         if (ret != AUDIO_SVC_ERROR_NONE) {
466                 msg_print(__LINE__, "error audio_svc_list_item_free");
467                 return -1;
468         }
469
470         //iterate all playlist and its tracks ==================================================
471         int plst_idx = -1;
472         int plst_count = -1;
473         AudioHandleType*playlists = NULL;
474         char plst_name[AUDIO_SVC_PLAYLIST_NAME_SIZE] = {0};
475
476         ret = audio_svc_count_playlist(db_handle, NULL, NULL, &plst_count);
477         if (ret != AUDIO_SVC_ERROR_NONE) {
478                 msg_print(__LINE__, "error audio_svc_count_playlist");
479                 return -1;
480         }
481         if(plst_count < 1) {
482                 msg_print(__LINE__, "there is no playlist");
483                 return -1;
484         }
485         else
486                 fprintf(stderr, "plst_count = [%d]\n", plst_count);
487         
488         ret = audio_svc_playlist_new(&playlists, plst_count);
489         if (ret != AUDIO_SVC_ERROR_NONE) {
490                 msg_print(__LINE__, "error audio_svc_playlist_new");
491                 return -1;
492         }
493
494         ret = audio_svc_get_playlist(db_handle, 
495                                 NULL, //filter_string,
496                                 NULL, //filter_string2,
497                                 0, //offset,
498                                 plst_count, //rows
499                                 playlists);
500         if (ret != AUDIO_SVC_ERROR_NONE) {
501                 msg_print(__LINE__, "error audio_svc_playlist_new");
502                 return -1;
503         }
504
505         int plst_id = -1;
506         for (idx = 0; idx < plst_count; idx++) {
507                 int size;
508                 char *playlist_name = NULL;
509                 char *playlist_thumbnail_path = NULL;
510                 
511                 audio_svc_playlist_get_val(playlists, idx, AUDIO_SVC_PLAYLIST_ID, &plst_id, AUDIO_SVC_PLAYLIST_NAME, &playlist_name, &size, AUDIO_SVC_PLAYLIST_THUMBNAIL_PATH, &playlist_thumbnail_path, &size,-1);
512                 fprintf(stderr, "**** Playlist Item Info****\n");
513                 fprintf(stderr, "** plst id: [%d], name: [%s], thumbnail_path: [%s]\n\n", plst_id, playlist_name, playlist_thumbnail_path);
514         }
515
516         ret = audio_svc_playlist_free(playlists);
517         if (ret != AUDIO_SVC_ERROR_NONE) {
518                 msg_print(__LINE__, "error audio_svc_playlist_new");
519                 return -1;
520         }
521
522         ret = audio_svc_count_playlist_item(db_handle, plst_id, "", "", &rows);
523         if (ret != AUDIO_SVC_ERROR_NONE) {
524                 msg_print(__LINE__, "error audio_svc_count_list_item");
525                 return -1;
526         }
527
528         if(rows < 1) {
529                 msg_print(__LINE__, "there is no item");
530                 return -1;
531         }
532         else
533                 fprintf(stderr, "rows = [%d]\n", rows);
534
535         ret = audio_svc_playlist_item_new(&tracks, rows);
536         if (ret != AUDIO_SVC_ERROR_NONE) {
537                 msg_print(__LINE__, "error to alloc memory for list item");
538                 return -1;
539         }
540         
541         ret = audio_svc_get_playlist_item(db_handle, 
542                 plst_id,
543                 NULL, //filter_string,
544                 NULL, //filter_string2,
545                 0, //offset,
546                 rows, //rows,
547                 tracks
548                 );
549         if (ret != AUDIO_SVC_ERROR_NONE) {
550                 msg_print(__LINE__, "error to get list item");
551                 return -1;
552         }
553
554         for (idx = 0; idx < rows; idx++) {
555                 char *audio_id = NULL, *title = NULL, *artist = NULL, *thumbname = NULL, *pathname = NULL;
556                 int uid = -1;
557                 int rating = 0;
558                 int duration = 0;
559                 int size = 0;
560                 int play_order = 0;     
561                                         
562                 ret = audio_svc_playlist_item_get_val(tracks, idx , 
563                         AUDIO_SVC_PLAYLIST_ITEM_UID, &uid,
564                         AUDIO_SVC_PLAYLIST_ITEM_AUDIO_ID, &audio_id, &size,
565                         AUDIO_SVC_PLAYLIST_ITEM_THUMBNAIL_PATH, &thumbname, &size,
566                         AUDIO_SVC_PLAYLIST_ITEM_TITLE, &title, &size,
567                         AUDIO_SVC_PLAYLIST_ITEM_ARTIST, &artist, &size,
568                         AUDIO_SVC_PLAYLIST_ITEM_PATHNAME, &pathname, &size,
569                         AUDIO_SVC_PLAYLIST_ITEM_DURATION, &duration,
570                         AUDIO_SVC_PLAYLIST_ITEM_RATING, &rating,
571                         AUDIO_SVC_PLAYLIST_ITEM_PLAY_ORDER, &play_order,
572                         -1);
573                 if (ret != AUDIO_SVC_ERROR_NONE) {
574                         msg_print(__LINE__, "error audio_svc_list_item_get_val");
575                         return -1;
576                 }
577
578                 fprintf(stderr, "       **uid = %d\n", uid);
579                 fprintf(stderr, "       **audio_id = %s\n", audio_id);
580                 fprintf(stderr, "       **thumbnail_path = %s\n", thumbname);
581                 fprintf(stderr, "       **title = %s\n", title);
582                 fprintf(stderr, "       **artist = %s\n", artist);
583                 fprintf(stderr, "       **path = %s\n", pathname);
584                 fprintf(stderr, "       **duration = %d\n", duration);
585                 fprintf(stderr, "       **rating = %d\n", rating);
586                 fprintf(stderr, "       **play_order = %d\n\n", play_order);
587         }       
588
589         ret = audio_svc_playlist_item_free(tracks);
590         if (ret != AUDIO_SVC_ERROR_NONE) {
591                 msg_print(__LINE__, "error audio_svc_list_item_free");
592                 return -1;
593         }
594         
595         ret = audio_svc_get_playlist_name_by_playlist_id(db_handle, plst_id, plst_name, AUDIO_SVC_PLAYLIST_NAME_SIZE);
596         if (ret != AUDIO_SVC_ERROR_NONE) {
597                 msg_print(__LINE__, "error audio_svc_get_playlist_name_by_playlist_id");
598                 return -1;
599         }
600         fprintf(stderr,"playlist id = %d, playlist name = %s\n", plst_id, plst_name);
601
602         //db close ==================================================
603         ret = media_svc_disconnect(db_handle);
604         if (ret != AUDIO_SVC_ERROR_NONE) {
605                 msg_print(__LINE__, "error to close music database");
606                 return -1;
607         }
608
609         return 0;
610 }
611
612
613 void insert_into_db(MediaSvcHandle * db_handle, const char * dir_path)
614 {
615         int audio_id = 300;
616         char thumb_path[AUDIO_SVC_PATHNAME_SIZE+1] = {0};
617
618         struct dirent *dp;
619
620         DIR *dir = opendir(dir_path);
621         while ((dp=readdir(dir)) != NULL) {
622                 char fpath[_POSIX_PATH_MAX];
623
624                 if (dp->d_name[0] == '.') {
625                         continue;
626                 }
627                 snprintf(fpath, sizeof(fpath), "%s/%s", dir_path, dp->d_name);
628
629                 fprintf(stderr,"[file path] : %s\n", fpath);
630
631                 int ret = audio_svc_insert_item(db_handle, AUDIO_SVC_STORAGE_PHONE, fpath, AUDIO_SVC_CATEGORY_MUSIC);
632                 if (ret != AUDIO_SVC_ERROR_NONE) {
633                         fprintf(stderr,"[error to insert music] : %s\n", fpath);
634                 }
635
636                 audio_id++;
637         }
638
639
640 }
641
642 void msg_print(int line, char *msg)
643 {
644         //fprintf(stderr, "\n");
645         //fprintf(stderr,"%s:%d\n", __FUNCTION__, __LINE__);
646         //fprintf(stderr, "+++++++++++++++++++++++++++++++++\n");
647         fprintf(stderr, "[%d]%s +++++\n", line, msg);
648         //fprintf(stderr, "+++++++++++++++++++++++++++++++++\n");
649         //fprintf(stderr, "+++++++++++++++++++++++++++++++++\n");
650         //fprintf(stderr, "\n");
651 }
652