2013-02-02 32 views
2

我現在正在播放裝載到myArray中的iPod庫中的歌曲,其格式爲iPodMusicPlayer當iOS中的Shuffle模式開啓時,NowPlayingItem的索引錯誤

我們可以使用indexOfNowPlayingItem從NowPlaying音樂獲取索引。

但是,當我Shuffle ModeonindexOfNowPlayingItem屬性的回報指數是完全錯誤的。

之前ShuffleMode關閉,indexOfNowPlayingItem可以正確使用。

但是,ShuffleMode打開時,indexOfNowPlayingItem計數僅增加1(++)。

indexOfNowPlayingItem++; 

不正確的ShuffleMode上。

那麼我怎樣才能得到正確的索引ShuffleMode上?

感謝您的幫助。

+0

同樣在這裏....你設法解決這個問題?任何幫助將非常感謝 –

+0

沒有兄弟。我找不到任何解決方案。 :( –

回答

2

我的解決方案是當你設置你的播放列表,還設置播放列表(索引,MPMediaEntityPropertyPersistentID)的一個NSMutableDictionary。

當您需要歌曲索引時,只需獲得歌曲持久性ID即可。

- (void) setPlaylistIndexDictionary:(MPMediaItemCollection *)playlistItems 
{ 
    playlistIndexDict = [[NSMutableDictionary alloc] init]; 
    NSNumber *count = [[NSNumber alloc] initWithInt:0]; 
    for (MPMediaItem *item in [playlistItems items]) { 
     [playlistIndexDict setObject:count forKey:[item valueForProperty:MPMediaEntityPropertyPersistentID]]; 
     count = [NSNumber numberWithInt:count.intValue + 1]; 
    } 
} 


- (NSString *) getCurrentSongId 
{ 
    NSString* songId = [[musicPlayer nowPlayingItem] valueForProperty:MPMediaEntityPropertyPersistentID]; 

    return songId; 
} 

使用:

NSString *songId = [musicController getCurrentSongId]; 
int songIndex = [[[musicController playlistIndexDict] objectForKey:songId] intValue]; 
相關問題