我正在尝试在 Spotify 中制作一个收集音频数据的程序。我在API中看到有一个回调get_audio_buffer_stats,它有stutter和samples。我尝试将其添加到程序中(我只是在修改点唱机示例),但即使我关闭 wifi 并等待歌曲停止播放,它也只会为口吃和采样打印 0。通过添加代码,我的意思是我为它制作了一个回调函数,并将它添加到会话回调中。我错过了什么吗?谁能帮我让这个回调工作?谢谢!我的代码如下:
static void get_audio_buffer_stats(sp_session *sess, sp_audio_buffer_stats *stats)
{
pthread_mutex_lock(&g_notify_mutex);
//log session data
stuttervariable = stats->stutter;
samplesvariable = stats->samples;
printf("stutter, %d\n", stuttervariable);
printf("samples, %d\n", samplesvariable);
pthread_cond_signal(&g_notify_cond);
pthread_mutex_unlock(&g_notify_mutex);
}
/**
* The session callbacks
*/
static sp_session_callbacks session_callbacks = {
.logged_in = &logged_in,
.notify_main_thread = ¬ify_main_thread,
.music_delivery = &music_delivery,
.metadata_updated = &metadata_updated,
.play_token_lost = &play_token_lost,
.log_message = NULL,
.end_of_track = &end_of_track,
.get_audio_buffer_stats = &get_audio_buffer_stats,
};