tizen 2.3 release
[framework/api/wav-player.git] / src / wav_player.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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. 
15 */
16
17
18 #define LOG_TAG "CAPI_MEDIA_WAV_PLAYER"
19
20 #include <mm_sound.h>
21 #include <mm_sound_private.h>
22 #include <stdio.h>
23 #include <limits.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <dlog.h>
27 #include "wav_player.h"
28 #include "wav_player_private.h"
29 #include <stdlib.h>
30
31
32 int wav_player_start(const char *path, sound_type_e type, wav_player_playback_completed_cb cb, void *user_data,  int * id)
33 {
34         int ret = MM_ERROR_NONE;
35         int player = -1;
36         char m_path[PATH_MAX];
37         void (*_completed_cb)(void *, int);
38         _completed_cb = NULL;
39         _cb_data *cb_data = NULL;
40
41
42         if( path == NULL)
43                 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
44
45         if( type < SOUND_TYPE_SYSTEM || type >= SOUND_TYPE_NUM )
46                 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
47
48         m_path[0] = '\0';
49         if( path[0] != '/' ){
50
51                 if( getcwd(m_path, PATH_MAX) != NULL){
52                         strncat(m_path, "/",PATH_MAX-strlen(m_path) );
53                 }
54         }
55         strncat(m_path, path, PATH_MAX-strlen(m_path));
56
57         if( cb ){
58                 _completed_cb = __internal_complete_cb;
59                 cb_data = (_cb_data *)malloc(sizeof(_cb_data));
60                 if(cb_data == NULL )
61                         return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_OPERATION);
62                 cb_data->cb = cb;
63                 cb_data->user_data = user_data;
64         }
65
66
67         ret = mm_sound_play_sound(m_path, type, _completed_cb , cb_data, &player);
68
69         if( ret == 0 && id != NULL){
70                 *id = player;
71         }
72
73         if( ret != 0 && cb_data != NULL)
74                 free(cb_data);
75
76         return __convert_wav_player_error_code(__func__, ret);
77 }
78
79 int wav_player_stop(int id)
80 {
81         return __convert_wav_player_error_code(__func__, mm_sound_stop_sound(id));
82 }
83