在iOS中打开洗牌模式时,NowPlayingItem的索引错误
我现在正在播放iPod库中的歌曲,该歌曲通过在iOS中打开洗牌模式时,NowPlayingItem的索引错误,ios,cocoa-touch,shuffle,mpmediaitem,Ios,Cocoa Touch,Shuffle,Mpmediaitem,我现在正在播放iPod库中的歌曲,该歌曲通过iPodMusicLayer加载到myArray中 我们可以使用indexOfNowPlayingItem从正在播放的音乐中获取索引 但是当iShuffle Mode处于打开状态时,indexOfNowPlayingItem属性的返回索引是完全错误的 在禁用ShuffleMode之前,可以使用并更正indexOfNowPlayingItem 但是,当ShuffleMode处于启用状态时,indexOfNowPlayingItem计数仅增加1(++) 那
iPodMusicLayer
加载到myArray中
我们可以使用indexOfNowPlayingItem
从正在播放的音乐中获取索引
但是当iShuffle Mode
处于打开状态时,indexOfNowPlayingItem
属性的返回索引是完全错误的
在禁用ShuffleMode
之前,可以使用并更正indexOfNowPlayingItem
但是,当ShuffleMode
处于启用状态时,indexOfNowPlayingItem计数仅增加1(++)
那样
indexOfNowPlayingItem++;
对于启用的ShuffleMode
,此选项不正确
那么,当ShuffleMode打开时,如何获得正确的索引呢
谢谢您的帮助。我的解决方案是,当您设置播放列表时,还要设置一个包含播放列表(index,mpmediateEntityPropertyTypersistentId)的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];
彼此彼此。。。。你解决了这个问题吗?任何帮助都会非常感激的。我找不到任何解决办法(