forked from enlightenment/enlightenment
add simple sound play api to play samples
This commit is contained in:
parent
b312bb3aa6
commit
91e797eab7
|
@ -293,6 +293,7 @@ dep_ecore_con = dependency('ecore-con' , required: true)
|
|||
dep_ecore_input = dependency('ecore-input' , required: true)
|
||||
dep_ecore_input_evas = dependency('ecore-input-evas', required: true)
|
||||
dep_ecore_evas = dependency('ecore-evas' , required: true)
|
||||
dep_ecore_audio = dependency('ecore-audio' , required: true)
|
||||
dep_evas = dependency('evas' , required: true)
|
||||
dep_edje = dependency('edje' , required: true)
|
||||
dep_efreet = dependency('efreet' , required: true)
|
||||
|
|
|
@ -155,6 +155,7 @@
|
|||
#include "e_comp_x_randr.h"
|
||||
#include "e_watchdog.h"
|
||||
#include "e_gesture.h"
|
||||
#include "e_sound.h"
|
||||
|
||||
#ifdef HAVE_WAYLAND
|
||||
# include "e_comp_wl.h"
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
#include <e.h>
|
||||
|
||||
#include <Ecore_Audio.h>
|
||||
|
||||
static int _can_sound_out = -1;
|
||||
static Eo *_sound_out = NULL;
|
||||
static int _outs = 0;
|
||||
static Ecore_Timer *_outs_end_timer = NULL;
|
||||
|
||||
static void
|
||||
_cb_out_fail(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
efl_unref(event->object);
|
||||
_sound_out = NULL;
|
||||
_can_sound_out = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_out_ready(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
|
||||
{
|
||||
_can_sound_out = 1;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_cb_outs_end_timer(void *data EINA_UNUSED)
|
||||
{
|
||||
efl_unref(_sound_out);
|
||||
_sound_out = NULL;
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_out_end(void)
|
||||
{
|
||||
if (_outs > 0) _outs--;
|
||||
if (_outs == 0)
|
||||
{
|
||||
if (_outs_end_timer) ecore_timer_del(_outs_end_timer);
|
||||
_outs_end_timer = ecore_timer_add(2.0, _cb_outs_end_timer, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_in_stopped(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
efl_unref(event->object);
|
||||
_out_end();
|
||||
}
|
||||
|
||||
E_API int
|
||||
e_sound_init(void)
|
||||
{
|
||||
ecore_audio_init();
|
||||
return 1;
|
||||
}
|
||||
|
||||
E_API int
|
||||
e_sound_shutdown(void)
|
||||
{
|
||||
if (_outs_end_timer)
|
||||
{
|
||||
ecore_timer_del(_outs_end_timer);
|
||||
_outs_end_timer = NULL;
|
||||
}
|
||||
if (_sound_out)
|
||||
{
|
||||
efl_unref(_sound_out);
|
||||
_sound_out = NULL;
|
||||
}
|
||||
ecore_audio_shutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
E_API void
|
||||
e_sound_file_play(const char *file, double vol)
|
||||
{
|
||||
Eo *in;
|
||||
char buf[PATH_MAX];
|
||||
|
||||
if (_can_sound_out == 0) return;
|
||||
if (!_sound_out)
|
||||
_sound_out = efl_add_ref
|
||||
(ECORE_AUDIO_OUT_PULSE_CLASS, NULL,
|
||||
efl_event_callback_add(efl_added,
|
||||
ECORE_AUDIO_OUT_PULSE_EVENT_CONTEXT_FAIL,
|
||||
_cb_out_fail, NULL),
|
||||
efl_event_callback_add(efl_added,
|
||||
ECORE_AUDIO_OUT_PULSE_EVENT_CONTEXT_READY,
|
||||
_cb_out_ready, NULL)
|
||||
);
|
||||
if (!_sound_out) return;
|
||||
|
||||
if (_outs_end_timer)
|
||||
{
|
||||
ecore_timer_del(_outs_end_timer);
|
||||
_outs_end_timer = NULL;
|
||||
}
|
||||
_outs++;
|
||||
snprintf(buf, sizeof(buf), "sound-file[%s]", file);
|
||||
in = efl_add_ref(ECORE_AUDIO_IN_SNDFILE_CLASS, NULL,
|
||||
efl_name_set(efl_added, buf),
|
||||
efl_event_callback_add(efl_added,
|
||||
ECORE_AUDIO_IN_EVENT_IN_STOPPED,
|
||||
_cb_in_stopped, NULL));
|
||||
if (!in)
|
||||
{
|
||||
_out_end();
|
||||
return;
|
||||
}
|
||||
if (!ecore_audio_obj_source_set(in, file))
|
||||
{
|
||||
efl_unref(in);
|
||||
_out_end();
|
||||
return;
|
||||
}
|
||||
ecore_audio_obj_volume_set(in, vol);
|
||||
if (!ecore_audio_obj_out_input_attach(_sound_out, in))
|
||||
{
|
||||
efl_unref(in);
|
||||
_out_end();
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#ifdef E_TYPEDEFS
|
||||
|
||||
#else
|
||||
#ifndef E_SOUND_H
|
||||
#define E_SOUND_H
|
||||
E_API int e_sound_init(void);
|
||||
E_API int e_sound_shutdown(void);
|
||||
E_API void e_sound_file_play(const char *file, double vol);
|
||||
#endif
|
||||
#endif
|
|
@ -25,6 +25,7 @@ deps_e = [
|
|||
dep_ecore_con,
|
||||
dep_ecore_input,
|
||||
dep_ecore_input_evas,
|
||||
dep_ecore_audio,
|
||||
dep_evas,
|
||||
dep_efreet,
|
||||
dep_efreet_mime,
|
||||
|
@ -59,6 +60,7 @@ requires_e = ' '.join([
|
|||
'ecore-con',
|
||||
'ecore-input',
|
||||
'ecore-input-evas',
|
||||
'ecore-audio',
|
||||
'evas',
|
||||
'efreet',
|
||||
'efreet-mime',
|
||||
|
@ -224,6 +226,7 @@ src = [
|
|||
'e_zoomap.c',
|
||||
'e_zone.c',
|
||||
'e_gesture.c',
|
||||
'e_sound.c',
|
||||
'efx/efx_bumpmapping.c',
|
||||
'efx/efx.c',
|
||||
'efx/efx_fade.c',
|
||||
|
@ -403,7 +406,8 @@ hdr = [
|
|||
'e_xsettings.h',
|
||||
'e_zoomap.h',
|
||||
'e_zone.h',
|
||||
'e_gesture.h'
|
||||
'e_gesture.h',
|
||||
'e_sound.h'
|
||||
]
|
||||
|
||||
if config_h.has('HAVE_WAYLAND') == true
|
||||
|
|
Loading…
Reference in New Issue