2 * Copyright (c) 2010 Samsung Electronics, Inc.
5 * This software is a confidential and proprietary information
6 * of Samsung Electronics, Inc. ("Confidential Information"). You
7 * shall not disclose such Confidential Information and shall use
8 * it only in accordance with the terms of the license agreement
9 * you entered into with Samsung Electronics.
12 * setting-common-sound.c
14 * Created on: Oct 16, 2013
19 #include <vconf-keys.h>
21 #include "setting-common-sound.h"
24 static player_h player;
25 static int is_player_created = 0;
26 static sound_type_e _sound_type;
28 //player_prelistening_mode_e _get_prelistening_mode(sound_type_e sound_type);
31 * @return zero on successful
37 int is_enable_sound = 0;
38 int is_enable_vibrate = 0;
40 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &is_enable_sound);
41 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &is_enable_vibrate);
43 if( is_enable_sound && !is_enable_vibrate ) // sound mode
45 mode = SOUND_MODE_SOUND;
47 else if( !is_enable_sound && is_enable_vibrate ) // vibration mode
49 mode = SOUND_MODE_VIBRATE;
51 else if( !is_enable_sound && !is_enable_vibrate ) // mute
53 mode = SOUND_MODE_MUTE;
58 static void _profile_player_prepare_cb(void *data)
60 DBG("Player is prepared. Start player");
62 if( !is_created_player() )
64 DBG("Player start cancel!!");
70 player_state_e play_state;
71 player_get_state(player, &play_state);
72 if (play_state == PLAYER_STATE_PAUSED || play_state == PLAYER_STATE_READY) {
74 err = player_start(player);
75 if (err != PLAYER_ERROR_NONE) { /* if directly return error.. */
76 DBG("Setting - player_start [%d]", err);
77 player_unprepare(player);
78 player_destroy(player);
79 is_player_created = 0;
84 DBG("Player state = %d. do not start", play_state);
89 int is_player_paused()
92 player_state_e state = -1;
93 player_get_state(player, &state);
94 if (state != PLAYER_STATE_PLAYING)
96 DBG("Setting - player is paused!!");
102 static int _profile_restart_player(void *data, char *ringtone_file, sound_type_e sound_type, int prelistening_enable)
104 player_state_e state = -1;
106 int prev_behavior = 0; /* instead of do_while(0) and break */
108 player_get_state(player, &state);
109 if (state == PLAYER_STATE_PLAYING) {
110 if (player_stop(player) != PLAYER_ERROR_NONE) {
111 DBG("Setting - mm player stop failed");
113 prev_behavior++; /* instead of do_while(0) and break */
117 if ((prev_behavior == 0) && (player_unprepare(player) != PLAYER_ERROR_NONE)) {
118 DBG("Setting - mm player unrealize failed");
120 prev_behavior++; /* instead of do_while(0) and break */
123 if (prev_behavior == 0) {
125 err = player_set_uri(player, ringtone_file);
126 if (err != PLAYER_ERROR_NONE) {
127 DBG("Setting - error to set attribute---profile_uri[%d]", err);
128 player_destroy(player);
129 is_player_created = 0;
134 if( prelistening_enable && sound_type != SOUND_TYPE_SYSTEM )
136 DBG("Setting - profile_play_sound is sessioning..");
138 player_prelistening_mode_e mode = _get_prelistening_mode(sound_type);
140 err = player_set_prelistening_mode(player, mode);
141 if (err != PLAYER_ERROR_NONE) {
142 DBG("Setting - error to player_set_session_prelistening[%d]", err);
143 player_destroy(player);
144 is_player_created = 0;
149 err = player_prepare_async(player, _profile_player_prepare_cb, NULL);
150 if (err != PLAYER_ERROR_NONE) {
151 DBG("Setting - realizing the player handle failed[%d]", err);
152 player_destroy(player);
153 is_player_created = 0;
160 player_prelistening_mode_e _get_prelistening_mode(sound_type_e sound_type)
162 player_prelistening_mode_e mode = mode = PLAYER_PRELISTENING_MODE_RINGTONE;
164 case SOUND_TYPE_MEDIA:
165 mode = PLAYER_PRELISTENING_MODE_MEDIA;
167 case SOUND_TYPE_RINGTONE:
168 mode = PLAYER_PRELISTENING_MODE_RINGTONE;
170 case SOUND_TYPE_NOTIFICATION:
171 mode = PLAYER_PRELISTENING_MODE_NOTIFICATION;
178 int profile_play_sound(void *data, void *cb, char *ringtone_file, float vol, sound_type_e sound_type, int prelistening_enable)
180 DBG("Setting - profile_play_sound is started. path: %s", ringtone_file);
181 DBG("Setting - profile_play_sound is creating.");
184 err = player_create(&player);
185 if( err != PLAYER_ERROR_NONE )
187 DBG("Setting - creating the player handle failed[%d]", err);
191 DBG("Setting - profile_play_sound is setting sound type.");
193 err = player_set_sound_type(player, sound_type);
194 if (err != PLAYER_ERROR_NONE) {
195 DBG("Setting - error to set sound_type[%d]", err);
196 player_destroy(player);
197 is_player_created = 0;
201 DBG("Setting - profile_play_sound is setting uri.");
203 err = player_set_uri(player, ringtone_file);
204 if (err != PLAYER_ERROR_NONE) {
205 DBG("Setting - error to set attribute---profile_uri[%d]", err);
206 player_destroy(player);
207 is_player_created = 0;
211 DBG("Setting - profile_play_sound is preparing.");
213 err = player_prepare_async(player, _profile_player_prepare_cb, NULL);
214 if (err != PLAYER_ERROR_NONE) {
215 DBG("Setting - realizing the player handle failed[%d]", err);
216 player_destroy(player);
217 is_player_created = 0;
221 DBG("Setting - waiting..");
223 _sound_type = sound_type;
225 is_player_created = 1;
230 int _profile_stop_sound(void *data)
232 player_state_e state = -1;
234 int prev_behavior = 0; /* instead of do_while(0) and break */
236 player_get_state(player, &state);
237 if (state == PLAYER_STATE_PLAYING) {
238 if (player_stop(player) != PLAYER_ERROR_NONE) {
239 DBG("Setting - mm player stop failed");
241 prev_behavior++; /* instead of do_while(0) and break */
245 //player_unset_completed_cb(*player);
246 //player_unset_interrupted_cb(*player);
248 if ((prev_behavior == 0) && (player_unprepare(player) != PLAYER_ERROR_NONE)) {
249 DBG("Setting - mm player unrealize failed");
251 prev_behavior++; /* instead of do_while(0) and break */
254 if ((prev_behavior == 0) && (player_destroy(player) != PLAYER_ERROR_NONE)) {
255 DBG("Setting - mm player destroy failed");
259 is_player_created = 0;
264 int is_created_player()
266 return is_player_created;
269 void set_looping(int enable)
271 if(is_created_player())
272 player_set_looping(player, enable);
274 ERR("player is not created!!");
277 int _close_player(void *data, sound_type_e type)
279 if ( is_created_player() )
281 if (_profile_stop_sound(data))
283 is_player_created = 0;
293 void play_sound(char * file_path, float volume, sound_type_e sound_type)
295 DBG("Setting - profile_play_sound function start ... : is_created_player() => (%d)", is_created_player());
296 if( !is_created_player() )
298 DBG("Setting - profile_play_sound)");
299 profile_play_sound(NULL, NULL, file_path, volume, sound_type, TRUE);
304 _profile_restart_player(NULL, file_path, sound_type, TRUE);
308 void play_sound_for_sound_mode(char * file_path, float volume, sound_type_e sound_type)
310 DBG("Setting - play_sound_for_sound_mode function start ...");
311 if( !is_created_player() )
313 DBG("Setting - play_sound_for_sound_mode)");
314 profile_play_sound(NULL, NULL, file_path, volume, sound_type, FALSE);
319 _profile_restart_player(NULL, file_path, sound_type, FALSE);