2012-02-27 142 views
1

我在將新創建的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方法的任何無效輸入。

我在這裏錯過了一些明顯的東西嗎?或者,移動功能是否有缺陷?

注意:我也嘗試使用此代碼移動先前創建的播放列表(即將名爲「My Playlist」的所有播放列表移動到文件夾中)。

編輯1:我已經調查了這一點,實際上得到了一些正在進行的動作。但是我不得不重寫一些代碼並執行幾次(或稍後階段)的移動。看起來這與SPSession中的數據不完全同步/最新(?)有關,因爲可能在以後使用新會話記錄時移動播放列表。

它可能是同步問題,即libspotify認爲SPPlaylistFolder已創建並將SPPlaylist s移動到它,但實際上尚未創建它?

回答

0

在參考this issue on cocoalibspotify更新了我的代碼之後,它工作得更好。我最初並沒有意識到如何與Spotify服務同步。例如,在Spotify桌面客戶端中反映這些更改可能需要幾分鐘的時間。

相關問題