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 "CAPI_MEDIA_WAV_PLAYER"
20 #include <sound_manager.h>
21 #include <sound_manager_internal.h>
23 #include <mm_sound_private.h>
29 #include "wav_player.h"
30 #include "wav_player_private.h"
34 int wav_player_start(const char *path, sound_type_e type, wav_player_playback_completed_cb cb, void *user_data, int * id)
36 int ret = MM_ERROR_NONE;
38 char m_path[PATH_MAX];
39 void (*_completed_cb)(void *, int);
41 _cb_data *cb_data = NULL;
45 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
47 if( type < SOUND_TYPE_SYSTEM || type >= SOUND_TYPE_NUM )
48 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
53 if( getcwd(m_path, PATH_MAX) != NULL){
54 strncat(m_path, "/",PATH_MAX-strlen(m_path) );
57 strncat(m_path, path, PATH_MAX-strlen(m_path));
60 _completed_cb = __internal_complete_cb;
61 cb_data = (_cb_data *)malloc(sizeof(_cb_data));
63 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_OPERATION);
65 cb_data->user_data = user_data;
69 ret = mm_sound_play_sound(m_path, type, _completed_cb , cb_data, &player);
71 if( ret == 0 && id != NULL){
75 if( ret != 0 && cb_data != NULL)
78 return __convert_wav_player_error_code(__func__, ret);
81 int wav_player_start_with_stream_info(const char *path, sound_stream_info_h stream_info, wav_player_playback_completed_cb cb, void *user_data, int *id)
83 int ret = MM_ERROR_NONE;
85 char m_path[PATH_MAX];
86 void (*_completed_cb)(void *, int);
88 _cb_data *cb_data = NULL;
89 char *stream_type = NULL;
94 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
96 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_WAV_PLAYER, &result);
98 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_NOT_SUPPORTED_TYPE);
100 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
102 return __convert_wav_player_error_code(__func__, ret);
103 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_id);
105 return __convert_wav_player_error_code(__func__, ret);
108 if( path[0] != '/' ){
110 if( getcwd(m_path, PATH_MAX) != NULL){
111 strncat(m_path, "/",PATH_MAX-strlen(m_path) );
114 strncat(m_path, path, PATH_MAX-strlen(m_path));
117 _completed_cb = __internal_complete_cb;
118 cb_data = (_cb_data *)malloc(sizeof(_cb_data));
120 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_OPERATION);
122 cb_data->user_data = user_data;
126 ret = mm_sound_play_sound_with_stream_info(m_path, stream_type, stream_id, _completed_cb , cb_data, &player);
128 if( ret == 0 && id != NULL){
132 if( ret != 0 && cb_data != NULL)
135 return __convert_wav_player_error_code(__func__, ret);
139 int wav_player_stop(int id)
141 return __convert_wav_player_error_code(__func__, mm_sound_stop_sound(id));