我有一个函数,我设置为回调,但事件正在发生,该函数没有被调用。还有什么我需要做的吗?
// static
int volume_change_callback(snd_mixer_elem_t* elem,
unsigned int mask) {
// Do stuff
}
snd_mixer_elem_set_callback(element, volume_change_callback);
您需要使用snd_mixer_handle_events()来实际调用回调。(http://www.alsa-project.org/alsa-doc/alsa-lib/group___mixer.html gae0cfb6b50ec2493281107b0649f87cb8)
查看mixer.c (https://fossies.org/dox/alsa-utils-1.0.29/amixer_8c_source.html)以获取处理事件的示例:
while (1) {
int res;
res = snd_mixer_wait(handle, -1);
if (res >= 0) {
printf("Poll ok: %in", res);
res = snd_mixer_handle_events(handle);
assert(res >= 0);
}
}