【问题标题】:Moving playlist to folder doesn't work将播放列表移动到文件夹不起作用
【发布时间】:2012-02-27 11:30:19
【问题描述】:

我在将新创建的 SPPlaylist 移动到(可能是新创建的)SPPlaylistFolder 时遇到问题。

这个想法是在用户的 Spotify 帐户中创建一个文件夹,我可以在其中添加从我的应用程序生成的播放列表。如果没有创建这样的文件夹,我将创建一个新的SPPlaylistFolder 并保存文件夹 id 以供以后使用。

这就是我正在做的事情(我已经省略了对这个主题不感兴趣的部分代码):

  1. 如果之前保存了folderId(即创建了一个文件夹),请使用该 ID 加载文件夹实例:

    ...
    
    NSError *error = nil;
    if (folderId > 0) {
      // try to fetch folder
      folder = [[SPSession sharedSession] playlistFolderForFolderId:folderId inContainer:container];
    }
    
    if (folder == nil) {
      // create folder
      folder = [container createFolderWithName:@"My Folder" error:&error];
    
      // save a reference to the folder in an instance var
      _appFolder = [folder retain];
    
      // (also saving folder.folderId in NSUserDefaults)
    }
    
    ...
    
  2. 创建一个SPPlaylist[[[SPSession sharedSession] userPlaylists] createPlaylistWithName:@"My Playlist"]

  3. 使用 KVO 观察容器的 playlists 属性并在创建播放列表时收到通知:[[[SPSession sharedSession] userPlaylists] addObserver:self forKeyPath:@"playlists" options:0 context:nil]

  4. 观察playlists 属性并将创建的播放列表移动到我的SPPlaylistFoldercontainerPlaylist 是我确定要移动的播放列表):

    ...
    // identify the index of the containerPlaylist
    NSInteger playlistIndex = [[[[SPSession sharedSession] userPlaylists] playlists] indexOfObject:containerPlaylist];
    
    // move playlist
    NSError * error = nil;
    BOOL success = [container movePlaylistOrFolderAtIndex:playlistIndex ofParent:nil toIndex:0 ofNewParent:_appFolder error:&error];
    if (success) {
      // This should be a great success. But the playlist hasn't been moved, although the error variable is nil.
    }
    
    ...
    

完成这些步骤后,播放列表和文件夹都已创建,但播放列表尚未移动。而且我没有收到任何错误,表明对 movePlaylistOrFolderAtIndex 方法的任何无效输入。

我在这里遗漏了一些明显的东西吗?或者移动功能是否存在某种缺陷?

注意:我还尝试使用此代码来移动之前创建的播放列表(即将所有名为“我的播放列表”的播放列表移动到文件夹中)。

编辑 1:我对此进行了更深入的调查,实际上正在进行一些动人的行动。但我不得不重写一些代码并多次执行移动(或在稍后阶段)。这似乎与 SPSession 中的数据未完全同步/最新(?)有关,因为稍后使用新会话登录时可以移动播放列表。

是否可能是同步问题,即 libspotify 认为 SPPlaylistFolder 已创建并将 SPPlaylists 移动到它,但实际上尚未创建?

【问题讨论】:

    标签: spotify playlists


    【解决方案1】:

    在参考this issue on cocoalibspotify 更新我的代码后,它运行得更好了。起初我没有意识到与 Spotify 服务同步是如何工作的。例如,更改可能需要几分钟时间才能在 Spotify 桌面客户端中反映出来。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多