2 * Copyright (c) 2011 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 #define LOG_TAG "TIZEN_N_WAV_PLAYER"
21 #include <mm_sound_private.h>
27 #include <wav_player.h>
31 typedef struct _cb_data_{
32 wav_player_playback_completed_cb cb;
39 static int __convert_wav_player_error_code(const char *func, int code){
40 int ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
41 char *errorstr = NULL;
45 ret = WAV_PLAYER_ERROR_NONE;
46 errorstr = "ERROR_NONE";
48 case MM_ERROR_INVALID_ARGUMENT:
49 case MM_ERROR_SOUND_INVALID_POINTER:
50 case WAV_PLAYER_ERROR_INVALID_PARAMETER:
51 ret = WAV_PLAYER_ERROR_INVALID_PARAMETER;
52 errorstr = "INVALID_PARAMETER";
54 case MM_ERROR_SOUND_INTERNAL:
55 ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
56 errorstr = "INVALID_OPERATION";
58 case MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE:
59 ret = WAV_PLAYER_ERROR_FORMAT_NOT_SUPPORTED;
60 errorstr = "FORMAT_NOT_SUPPORTED";
63 ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
64 errorstr = "INVALID_OPERATION";
67 LOGE( "[%s] %s(0x%08x)",func, errorstr, ret);
72 static void __internal_complete_cb(void *user_data){
73 _cb_data * cb_data = (_cb_data*)user_data;
78 cb_data->cb(cb_data->id, cb_data->uesr_data);
83 int wav_player_start(const char *path, sound_type_e type , wav_player_playback_completed_cb cb, void *user_data, int * id){
86 char m_path[PATH_MAX];
87 void (*_completed_cb)(void *);
89 _cb_data *cb_data = NULL;
93 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
95 if( type < SOUND_TYPE_SYSTEM || type > SOUND_TYPE_CALL )
96 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
101 if( getcwd(m_path, PATH_MAX) != NULL){
102 strncat(m_path, "/",PATH_MAX-strlen(m_path) );
105 strncat(m_path, path, PATH_MAX-strlen(m_path));
108 _completed_cb = __internal_complete_cb;
109 cb_data = (_cb_data *)malloc(sizeof(_cb_data));
111 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_OPERATION);
113 cb_data->uesr_data = user_data;
116 ret = mm_sound_play_sound(m_path, type, _completed_cb , cb_data, &player);
117 if( ret == 0 && id != NULL)
119 if( ret == 0 && cb_data )
120 cb_data->id = player;
122 if( ret != 0 && cb_data != NULL)
126 return __convert_wav_player_error_code(__func__, ret);
129 int wav_player_stop(int id){
130 return __convert_wav_player_error_code(__func__, mm_sound_stop_sound(id));