该 api 的文档非常差,我很困惑。该方法sp_search采用参数(sp_search* 搜索,int index)。如何创建sp_search对象?
libspotify的完整文档可以在这里找到。搜索功能位于"模块"下,然后位于"搜索"下。
libspotify 附带的spshell
示例包含search.c
文件中搜索的完整实现。它是这样完成的:
sp_search *newSearch = sp_search_create(session,
"foo fighters", //query
0, // track_offset
100, //track_count
0, //album_offset
100, //album_count
0, //artist_offset
100, //artist_count
0, // playlist_offset,
100, // playlist_count
SP_SEARCH_STANDARD, // search type
&search_complete, //callback
NULL); // userdata
void search_complete(sp_search *result, void *userdata) {
int trackCount = sp_search_num_tracks(search);
for (int currentTrack = 0; currentTrack < trackCount; currentTrack++) {
sp_track *track = sp_search_track(search, currentTrack);
// Do something with track...
}
}