내 MPMusicPlayerController에 문제가 있습니다. 그것은 iPod 뮤직 플레이어이고, appmusicplayer가 아닙니다. 내 문제는 올바른 순서로 큐를 재생할 수 없다는 것입니다. 더 자세히 설명하겠습니다.MPMusicPlayerController 큐 문제
iPod 픽커를 사용하여 미디어 컬렉션을 선택하고 음악 플레이어의 큐에 추가합니다. 이 작업을 수행하면 컬렉션의 항목이 테이블보기로 표시됩니다. 그런 다음 사용자는이 대기열을 "재생"할 수 있습니다. 그러나 아이팟 컨트롤로 재생 목록을 탐색하려고 할 때 어떤 이유로 큐가 잘못된 순서로 표시됩니다.
미디어 선택 도구 호출이 방법 :
-(void)updatePlayerQueueWithMediaCollection:(MPMediaItemCollection *)collection {
if (collection) {
// If there's no playback queue yet...
if (self.userMediaItemCollection == nil) {
[self setUserMediaItemCollection: collection];
[self.musicPlayer setQueueWithItemCollection:self.userMediaItemCollection];
} else {
BOOL wasPlaying = NO;
if (self.musicPlayer.playbackState == MPMusicPlaybackStatePlaying) {
wasPlaying = YES;
}
// Save the now-playing item and its current playback time.
MPMediaItem *nowPlayingItem = self.musicPlayer.nowPlayingItem;
NSTimeInterval currentPlaybackTime = self.musicPlayer.currentPlaybackTime;
// Combine the previously-existing media item collection with the new one
NSMutableArray *combinedMediaItems =
[[self.userMediaItemCollection items] mutableCopy];
NSArray *newMediaItems = [collection items];
[combinedMediaItems addObjectsFromArray: newMediaItems];
[self setUserMediaItemCollection:[MPMediaItemCollection collectionWithItems:(NSArray *) combinedMediaItems]];
[self.musicPlayer setQueueWithItemCollection: self.userMediaItemCollection];
// Restore the now-playing item and its current playback time.
self.musicPlayer.nowPlayingItem = nowPlayingItem;
self.musicPlayer.currentPlaybackTime = currentPlaybackTime;
if (wasPlaying) {
[self.musicPlayer play];
}
}
}
int i = 0;
for (MPMediaItem *item in [self.userMediaItemCollection items]){
NSLog(@"playback queue item %i has title %@",i, [item valueForKey:MPMediaItemPropertyTitle]);
i++;
}
}
간단한만큼,이 애플에서 직접 촬영 몇 가지 코드입니다. 하단의 NSLog가 대기열을 로그 아웃하고 올바른 것으로 나타납니다.
여기에서 사용자는 재생 버튼을 클릭하여 대기열을 재생할 수 있습니다.
-(void) setNowPlayingItem:(MPMediaItem *)nowPlayingItem {
_nowPlayingItem = nowPlayingItem;
[MusicPlayerManager sharedMusicPlayer].musicPlayer.nowPlayingItem = nowPlayingItem;
[[MusicPlayerManager sharedMusicPlayer].musicPlayer play];
NSLog(@"index of now playing item %i", [[MusicPlayerManager sharedMusicPlayer].musicPlayer indexOfNowPlayingItem]);
}
이의있는 tableview의 indexpath에서 올바른 노래를 재생하지만 :
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
if ([segue.destinationViewController respondsToSelector:@selector(setNowPlayingItem:)]) {
NSArray *items = [[MusicPlayerManager sharedMusicPlayer].userMediaItemCollection items];
[segue.destinationViewController performSelector:@selector(setNowPlayingItem:) withObject:[items objectAtIndex:indexPath.row]];
}
if ([segue.destinationViewController respondsToSelector:@selector(setTrackList:)]) {
[segue.destinationViewController performSelector:@selector(setTrackList:) withObject:[MusicPlayerManager sharedMusicPlayer].userMediaItemCollection];
NSLog(@"tracklist from tltbvc looks like %@", [MusicPlayerManager sharedMusicPlayer].userMediaItemCollection);
}
} 대상 뷰 컨트롤러에서
에서, setNowPlayingItem 방법은 다음과 같습니다 :이 같은 것을 설정 어떤 이유로 인덱스가 더 이상 테이블의 위치와 일치하지 않습니다. 행 인덱스 0의 노래가 ABC 인 경우 플레이어는 ABC를 재생하지만 더 이상 0이 아닌 indexOfNowPlayingItem을 로그 아웃합니다. 앞으로 건너 뛰고 다시 시도하면 대기열의 순서가 더 이상 유지되지 않습니다. 이 셔플 on으로 설정 한 어떤 이유로 와우 너무 많은 코드를
와우. 이 질문을 삭제하지 않아서 두 시간의 두통을 끝내 주셔서 감사합니다. –