Fire Fist
Fire Fist

Reputation: 7050

How to retrieve Playlist from iPod Library in iOS?

I am trying to retrieve playlist from iPod Library with MPMediaQuery in iOS. And i want to show in UITableView.

Here is my codes in viewDidLoad.

MPMediaQuery *myQuery = [[MPMediaQuery alloc] init];
[myQuery setGroupingType: MPMediaGroupingPlaylist];
arrayOfPlaylist = [myQuery collections];

And In UITableViewCell Method

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    for(int i=0;i<self.arrayOfPlaylist.count;i++)
    {
        dic = [self.arrayOfPlaylist objectAtIndex:0];
        cell.textLabel.font = [UIFont systemFontOfSize:10];
        cell.textLabel.text = [NSString stringWithFormat:@"%@",[self.arrayOfPlaylist objectAtIndex:indexPath.row]];
    }

    return cell;

After I write above codes , in my UITableView I only got following messages:

<MPConcreteMediaPlaylist : 0x1e51afd0>

I don't know what is that and how to convert playlist name into String. When I test with NSLog method , my playlist count is correct.

But I only got the above message and no playlist name in UITableView.

I am just a beginner in iOS.

Please help me to show playlist in UITableView.

Upvotes: 3

Views: 2142

Answers (2)

Fire Fist
Fire Fist

Reputation: 7050

I got my answer for my own question.

here is it.

MPMediaQuery *query = [MPMediaQuery playlistsQuery]; 
NSArray *playlists = [query collections];

for(int i = 0; i < [playlists count]; i++) 
{
NSLog(@"Playlist : %@", [[playlists objectAtIndex:i] valueForProperty: MPMediaPlaylistPropertyName]);
}

Upvotes: 3

Paresh Navadiya
Paresh Navadiya

Reputation: 38249

Playlist can be explored like this:

MPMediaQuery *myQuery = [[MPMediaQuery alloc] init];

arrayOfPlaylist = [myQuery collections];

for (MPMediaPlaylist *playlist in arrayOfPlaylist) {
    NSLog (@"Playlist :%@", [playlist valueForProperty: MPMediaPlaylistPropertyName]);
    NSArray *songs = [playlist items];
    for (MPMediaItem *song in songs) {
        NSString *strSongTitle =
            [song valueForProperty: MPMediaItemPropertyTitle];
        NSLog (@"Title : %@", strSongTitle);
    }
}

Upvotes: 9

Related Questions