Question

I can show music library on UITableView.

  songsArray = [[NSMutableArray alloc]init];
MPMediaQuery *playlistQuery = [[MPMediaQuery alloc]init];
[playlistQuery setGroupingType:MPMediaGroupingTitle];
songArray = [playlistQuery items];
for (MPMediaItem *song in songArray) {
    NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];        
    [songsArray addObject:songTitle];
}
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:                (NSIndexPath *)indexPath {
    cell.textLabel.text = [songsArray objectAtIndex:row];
[cell.textLabel setTextColor:[UIColor whiteColor]];

But I can't play music when I selected UITableView Cell.

    NSUInteger row = indexPath.row;

NSString *selectedSong = [songsArray objectAtIndex:row];
MPMusicPlayerController *appPlayer = [MPMusicPlayerController iPodMusicPlayer];

[appPlayer setQueueWithQuery:selectedSong];

[appPlayer play];

}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top