【问题标题】:Searching for playlists in libspotify, can't seem to get metadata from the results在 libspotify 中搜索播放列表,似乎无法从结果中获取元数据
【发布时间】:2013-03-01 05:52:04
【问题描述】:

不确定搜索播放列表的正确处理,对艺术家、曲目、专辑没有问题。 开发人员资源似乎不包括这一点,当然这是我似乎正在努力解决的部分。

https://developer.spotify.com/technologies/libspotify/docs/12.1.45/search_8c-example.html 进行搜索但不处理播放列表结果。

search.c 中的 spshell 有此引用,但仅名称并没有帮助,我看到 sp_search_playlist 被注释掉了,但它没有记录。我以为它会返回一些我可以传递给 sp_playlist_num_tracks、sp_playlist_name 等的东西。但这似乎不起作用。

for (i = 0; i < sp_search_num_playlists(search); ++i) {
    // print some readily available metadata, the rest will
    // be available from the sp_playlist object loaded through
    // sp_search_playlist().
    printf("  Playlist \"%s\"\n", sp_search_playlist_name(search, i));
}

那么如何正确地将搜索播放列表转换为一些元数据和曲目?

任何帮助或建议都会很棒!

【问题讨论】:

    标签: libspotify


    【解决方案1】:

    我不确定为什么它不在在线文档中,但 sp_search_playlist 记录在 api.h 中:

    /**
     * Load the playlist at the given index in the given search object
     *
     * @param[in]  search     Search object
     * @param[in]  index      Index of the wanted playlist. Should be in the interval [0, sp_search_num_playlists() - 1]
     *
     * @return                A playlist object. This reference is owned by the caller and should be released with sp_playlist_release()
     */
    SP_LIBEXPORT(sp_playlist *) sp_search_playlist(sp_search *search, int index);
    

    请注意,与 API 的许多类似部分不同,它表示调用者拥有引用。

    或者,如果您因为记录不充分而对使用它感到不舒服,您可以改为从搜索中获取播放列表 URI,从中创建一个链接,然后从该链接创建一个播放列表。

    【讨论】:

    • 这两种方法我都试过了,我可以通过 sp_search_playlist_name 获取播放列表名称,通过 sp_search_playlist_uri 获取播放列表链接。将 sp_link_create_from_string 与我假设的结果一起使用应该允许我调用 sp_playlist_create。从那里像 sp_playlist_num_tracks 这样的 api 调用返回 0, sp_playlist_get_description 什么也不返回。使用 sp_search_playlist 然后直接调用 sp_playlist_num_tracks 和 sp_playlist_get_description 仍然不会返回有意义的结果。好像我在这里遗漏了一些东西。
    • 如果你在 spshell 中修改 search.c 以添加 sp_search_playlist 如下... for (i = 0; i
    • 如果我将它添加到循环中,也会发生同样的情况, const char *uri = sp_search_playlist_uri(search, i); sp_link *link =sp_link_create_from_string(uri ); sp_playlist * list = sp_playlist_create(g_session, 链接); int count = sp_playlist_num_tracks(list); const char *desc = sp_playlist_get_description(list);
    • 您是否等待播放列表加载?你有没有必要时调用 sp_session_process_events 的事件循环?
    【解决方案2】:

    好的,我似乎已经解决了这个问题。我需要等到 playlist_update_in_progress 并且 done 标志为真才能获取数据。希望这对其他人有帮助。

    【讨论】:

      猜你喜欢
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多