2 * Copyright (c) 2000 - 2013 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.
18 * setting-common-sound.c
20 * Created on: Oct 16, 2013
25 #include <vconf-keys.h>
27 #include "setting-common-sound.h"
30 static player_h player;
31 static int is_player_created = 0;
32 static sound_type_e _sound_type;
36 * @return zero on successful
42 int is_enable_sound = 0;
43 int is_enable_vibrate = 0;
45 vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &is_enable_sound);
46 vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &is_enable_vibrate);
48 if( is_enable_sound && !is_enable_vibrate ) // sound mode
50 mode = SOUND_MODE_SOUND;
52 else if( !is_enable_sound && is_enable_vibrate ) // vibration mode
54 mode = SOUND_MODE_VIBRATE;
56 else if( !is_enable_sound && !is_enable_vibrate ) // mute
58 mode = SOUND_MODE_MUTE;
63 static void _profile_player_prepare_cb(void *data)
65 DBG("Player is prepared. Start player");
67 if( !is_created_player() )
69 DBG("Player start cancel!!");
75 player_state_e play_state;
76 player_get_state(player, &play_state);
77 if (play_state == PLAYER_STATE_PAUSED || play_state == PLAYER_STATE_READY) {
79 err = player_start(player);
80 if (err != PLAYER_ERROR_NONE) { /* if directly return error.. */
81 DBG("Setting - player_start [%d]", err);
82 player_unprepare(player);
83 player_destroy(player);
84 is_player_created = 0;
89 DBG("Player state = %d. do not start", play_state);
94 int is_player_paused()
97 player_state_e state = -1;
98 player_get_state(player, &state);
99 if (state != PLAYER_STATE_PLAYING)
101 DBG("Setting - player is paused!!");
107 static int _profile_restart_player(void *data, char *ringtone_file, sound_type_e sound_type, int prelistening_enable)
109 player_state_e state = -1;
111 int prev_behavior = 0; /* instead of do_while(0) and break */
113 player_get_state(player, &state);
114 if (state == PLAYER_STATE_PLAYING) {
115 if (player_stop(player) != PLAYER_ERROR_NONE) {
116 DBG("Setting - mm player stop failed");
118 prev_behavior++; /* instead of do_while(0) and break */
122 if ((prev_behavior == 0) && (player_unprepare(player) != PLAYER_ERROR_NONE)) {
123 DBG("Setting - mm player unrealize failed");
125 prev_behavior++; /* instead of do_while(0) and break */
128 if (prev_behavior == 0) {
130 err = player_set_uri(player, ringtone_file);
131 if (err != PLAYER_ERROR_NONE) {
132 DBG("Setting - error to set attribute---profile_uri[%d]", err);
133 player_destroy(player);
134 is_player_created = 0;
138 err = player_prepare_async(player, _profile_player_prepare_cb, NULL);
139 if (err != PLAYER_ERROR_NONE) {
140 DBG("Setting - realizing the player handle failed[%d]", err);
141 player_destroy(player);
142 is_player_created = 0;
149 int profile_play_sound(void *data, void *cb, char *ringtone_file, float vol, sound_type_e sound_type, int prelistening_enable)
151 DBG("Setting - profile_play_sound is started. path: %s", ringtone_file);
152 DBG("Setting - profile_play_sound is creating.");
155 err = player_create(&player);
156 if( err != PLAYER_ERROR_NONE )
158 DBG("Setting - creating the player handle failed[%d]", err);
162 DBG("Setting - profile_play_sound is setting sound type.");
164 err = player_set_sound_type(player, sound_type);
165 if (err != PLAYER_ERROR_NONE) {
166 DBG("Setting - error to set sound_type[%d]", err);
167 player_destroy(player);
168 is_player_created = 0;
172 DBG("Setting - profile_play_sound is setting uri.");
174 err = player_set_uri(player, ringtone_file);
175 if (err != PLAYER_ERROR_NONE) {
176 DBG("Setting - error to set attribute---profile_uri[%d]", err);
177 player_destroy(player);
178 is_player_created = 0;
182 DBG("Setting - profile_play_sound is preparing.");
184 //err = player_prepare(player);
185 err = player_prepare_async(player, _profile_player_prepare_cb, NULL);
186 if (err != PLAYER_ERROR_NONE) {
187 DBG("Setting - realizing the player handle failed[%d]", err);
188 player_destroy(player);
189 is_player_created = 0;
193 DBG("Setting - waiting..");
195 _sound_type = sound_type;
197 is_player_created = 1;
202 int _profile_stop_sound(void *data)
204 player_state_e state = -1;
206 int prev_behavior = 0; /* instead of do_while(0) and break */
208 player_get_state(player, &state);
209 if (state == PLAYER_STATE_PLAYING) {
210 if (player_stop(player) != PLAYER_ERROR_NONE) {
211 DBG("Setting - mm player stop failed");
213 prev_behavior++; /* instead of do_while(0) and break */
217 //player_unset_completed_cb(*player);
218 //player_unset_interrupted_cb(*player);
220 if ((prev_behavior == 0) && (player_unprepare(player) != PLAYER_ERROR_NONE)) {
221 DBG("Setting - mm player unrealize failed");
223 prev_behavior++; /* instead of do_while(0) and break */
226 if ((prev_behavior == 0) && (player_destroy(player) != PLAYER_ERROR_NONE)) {
227 DBG("Setting - mm player destroy failed");
231 is_player_created = 0;
236 int is_created_player()
238 return is_player_created;
241 void set_looping(int enable)
243 if(is_created_player())
244 player_set_looping(player, enable);
246 ERR("player is not created!!");
249 int _close_player(void *data, sound_type_e type)
251 if ( is_created_player() )
253 if (_profile_stop_sound(data))
255 is_player_created = 0;
265 void play_sound(char * file_path, float volume, sound_type_e sound_type)
267 DBG("Setting - profile_play_sound function start ...");
268 if( !is_created_player() )
270 DBG("Setting - profile_play_sound)");
271 profile_play_sound(NULL, NULL, file_path, volume, sound_type, TRUE);
276 _profile_restart_player(NULL, file_path, sound_type, TRUE);
280 void play_sound_for_sound_mode(char * file_path, float volume, sound_type_e sound_type)
282 DBG("Setting - play_sound_for_sound_mode function start ...");
283 if( !is_created_player() )
285 DBG("Setting - play_sound_for_sound_mode)");
286 profile_play_sound(NULL, NULL, file_path, volume, sound_type, FALSE);
291 _profile_restart_player(NULL, file_path, sound_type, FALSE);