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, NULL, "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);*/
69 return g_strdup(name);
71 metadata_extractor_destroy(metadata);
72 return g_strdup(name);
75 return g_strdup(name);
79 int get_filelist_from_dir_path(char *path, Eina_List **file_list)
85 retvm_if(path == NULL, -1, "dir path is null");
86 retvm_if(file_list == NULL, -1, "file_list is null");
94 while ((ent = readdir(pDir)) != NULL) {
95 fileNodeInfo *pNode = NULL;
97 if (strncmp(ent->d_name, ".", 1) == 0 || strcmp(ent->d_name, "..") == 0) {
101 if ((ent->d_type & DT_REG) == 0) {
105 pNode = (fileNodeInfo *) malloc(sizeof(fileNodeInfo));
109 memset(pNode, 0, sizeof(fileNodeInfo));
111 pNode->path = g_strdup(path);
112 pNode->name = g_strdup(ent->d_name);
113 pNode->media_name = get_media_basename(pNode->path, pNode->name);
115 *file_list = eina_list_append(*file_list, pNode);
123 void ringtone_play_sound(const char *sound_file, player_h **mp_handle)
126 player_h *player = calloc(1, sizeof(player_h));
128 SETTING_TRACE_ERROR("failed to calloc player_h");
132 sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
133 sound_manager_set_media_session_option(SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START, SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY);
135 int err = player_create(player);
136 if (err != PLAYER_ERROR_NONE) {
137 SETTING_TRACE_ERROR("creating the player handle failed[%d]",
143 err = player_set_uri(*player, sound_file);
144 if (err != PLAYER_ERROR_NONE) {
145 SETTING_TRACE_ERROR("error to set attribute---profile_uri[%d]",
147 player_destroy(*player);
152 err = player_prepare(*player);
153 if (err != PLAYER_ERROR_NONE) {
154 SETTING_TRACE_ERROR("realizing the player handle failed[%d]",
156 player_destroy(*player);
161 player_state_e state = -1;
162 player_get_state(*player, &state);
163 SETTING_TRACE("state:%d", state);
165 if (state != PLAYER_STATE_READY) {
166 SETTING_TRACE_ERROR("state of player is invalid %d", err);
167 player_unprepare(*player);
168 player_destroy(*player);
173 /*player_set_completed_cb(*player, cb, data); */
175 err = player_start(*player);
176 if (err != PLAYER_ERROR_NONE) { /* if directly return error.. */
177 SETTING_TRACE_ERROR("player_start [%d]", err);
178 player_unset_completed_cb(*player);
179 player_unprepare(*player);
180 player_destroy(*player);
189 *@brief the function for sound balance stop the sound.
193 void ringtone_stop_sound(void *data)
196 setting_retm_if(data == NULL, "data is NULL");
197 SettingRingtoneUG *ad = (SettingRingtoneUG *) data;
198 setting_retm_if(ad->mp_ringtone == NULL, "ad->mp_ringtone is NULL");
199 player_state_e state = -1;
201 player_h player = *(ad->mp_ringtone);
202 player_get_state(*ad->mp_ringtone, &state);
203 if (state == PLAYER_STATE_PLAYING) {
204 if (player_stop(player) != PLAYER_ERROR_NONE) {
205 SETTING_TRACE("mm player stop failed");
206 ret = SETTING_MMPLAYER_STOP_ERR;
210 /*player_unset_completed_cb(player); */
212 if ((ret == 0) && (player_unprepare(player) != PLAYER_ERROR_NONE)) {
213 SETTING_TRACE("mm player unrealize failed");
214 ret = SETTING_MMPLAYER_UNREALIZE_ERR;
217 if ((ret == 0) && (player_destroy(player) != PLAYER_ERROR_NONE)) {
218 SETTING_TRACE("mm player destroy failed");
219 ret = SETTING_MMPLAYER_DESTROY_ERR;
222 sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
224 FREE(ad->mp_ringtone);
225 ad->mp_ringtone = NULL;