4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "setting-ringtone-util.h"
24 inline char *strlower(char *str)
26 if (!str) return NULL;
28 for (; *str != '\0 '; str++)
34 char *get_filename_from_fullname(const char *fullname)
36 retvm_if(fullname == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "fullname == NULL");
39 snprintf(tmp, sizeof(tmp), "%s", fullname);
41 char *name = strrchr(tmp, '.');
48 char *get_media_basename(const char *dir_path, const char *name)
50 if (isEmptyStr(dir_path) || isEmptyStr(name)) {
54 char path[512] = {0, };
55 snprintf(path, sizeof(path), "%s/%s", dir_path, name);
57 metadata_extractor_h metadata = NULL;
59 int ret = metadata_extractor_create(&metadata);
60 if (ret == METADATA_EXTRACTOR_ERROR_NONE && metadata) {
61 ret = metadata_extractor_set_path(metadata, path);
62 if (ret == METADATA_EXTRACTOR_ERROR_NONE) {
63 ret = metadata_extractor_get_metadata(metadata, METADATA_TITLE, &title);
64 metadata_extractor_destroy(metadata);
66 return (char *)g_strdup(title);
68 return g_strdup(name);
70 metadata_extractor_destroy(metadata);
71 return g_strdup(name);
74 return g_strdup(name);
78 int get_filelist_from_dir_path(char *path, Eina_List **file_list)
84 retvm_if(path == NULL, -1, "dir path is null");
85 retvm_if(file_list == NULL, -1, "file_list is null");
93 while ((ent = readdir(pDir)) != NULL) {
94 fileNodeInfo *pNode = NULL;
96 if (strncmp(ent->d_name, ".", 1) == 0 || strcmp(ent->d_name, "..") == 0) {
100 if ((ent->d_type & DT_REG) == 0) {
104 pNode = (fileNodeInfo *) malloc(sizeof(fileNodeInfo));
108 memset(pNode, 0, sizeof(fileNodeInfo));
110 pNode->path = g_strdup(path);
111 pNode->name = g_strdup(ent->d_name);
112 pNode->media_name = get_media_basename(pNode->path, pNode->name);
114 *file_list = eina_list_append(*file_list, pNode);
122 void ringtone_play_sound(const char *sound_file, player_h **mp_handle)
125 player_h *player = calloc(1, sizeof(player_h));
127 SETTING_TRACE_ERROR("failed to calloc player_h");
131 sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
132 sound_manager_set_media_session_option(SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START, SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY);
134 int err = player_create(player);
135 if (err != PLAYER_ERROR_NONE) {
136 SETTING_TRACE_ERROR("creating the player handle failed[%d]",
142 err = player_set_uri(*player, sound_file);
143 if (err != PLAYER_ERROR_NONE) {
144 SETTING_TRACE_ERROR("error to set attribute---profile_uri[%d]",
146 player_destroy(*player);
151 err = player_prepare(*player);
152 if (err != PLAYER_ERROR_NONE) {
153 SETTING_TRACE_ERROR("realizing the player handle failed[%d]",
155 player_destroy(*player);
160 player_state_e state = -1;
161 player_get_state(*player, &state);
162 SETTING_TRACE("state:%d", state);
164 if (state != PLAYER_STATE_READY) {
165 SETTING_TRACE_ERROR("state of player is invalid %d", err);
166 player_unprepare(*player);
167 player_destroy(*player);
172 /*player_set_completed_cb(*player, cb, data); */
174 err = player_start(*player);
175 if (err != PLAYER_ERROR_NONE) { /* if directly return error.. */
176 SETTING_TRACE_ERROR("player_start [%d]", err);
177 player_unset_completed_cb(*player);
178 player_unprepare(*player);
179 player_destroy(*player);
188 *@brief the function for sound balance stop the sound.
192 void ringtone_stop_sound(void *data)
195 setting_retm_if(data == NULL, "data is NULL");
196 SettingRingtoneUG *ad = (SettingRingtoneUG *) data;
197 setting_retm_if(ad->mp_ringtone == NULL, "ad->mp_ringtone is NULL");
198 player_state_e state = -1;
200 player_h player = *(ad->mp_ringtone);
201 player_get_state(*ad->mp_ringtone, &state);
202 if (state == PLAYER_STATE_PLAYING) {
203 if (player_stop(player) != PLAYER_ERROR_NONE) {
204 SETTING_TRACE("mm player stop failed");
205 ret = SETTING_MMPLAYER_STOP_ERR;
209 /*player_unset_completed_cb(player); */
211 if ((ret == 0) && (player_unprepare(player) != PLAYER_ERROR_NONE)) {
212 SETTING_TRACE("mm player unrealize failed");
213 ret = SETTING_MMPLAYER_UNREALIZE_ERR;
216 if ((ret == 0) && (player_destroy(player) != PLAYER_ERROR_NONE)) {
217 SETTING_TRACE("mm player destroy failed");
218 ret = SETTING_MMPLAYER_DESTROY_ERR;
221 sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
223 FREE(ad->mp_ringtone);
224 ad->mp_ringtone = NULL;