我有一个函数,我将其设置为回调,但事件正在发生且函数未被调用。还有什么我需要做的吗?
// static
int volume_change_callback(snd_mixer_elem_t* elem,
unsigned int mask) {
// Do stuff
}
snd_mixer_elem_set_callback(element, volume_change_callback);
答案 0 :(得分:3)
您需要使用snd_mixer_handle_events()来实际调用callback。 (http://www.alsa-project.org/alsa-doc/alsa-lib/group___mixer.html#gae0cfb6b50ec2493281107b0649f87cb8)
查看amixer.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: %i\n", res);
res = snd_mixer_handle_events(handle);
assert(res >= 0);
}
}