views:

507

answers:

3

Hello, and thanks in advance for you time.

I am trying to filter out certain types of playlists for an iphone app (genius and On-the-go, specifically). the documentation says that the property attribute MPMediaPlaylistPropertyPlaylistAttributes will return the attributes associated with a playlist in the form of an NSNumber containing an NSInteger object. The documentation also lists these possible values for that property:

e

num {
   MPMediaPlaylistAttributeNone    = 0,
   MPMediaPlaylistAttributeOnTheGo = (1 << 0),
   MPMediaPlaylistAttributeSmart   = (1 << 1),
   MPMediaPlaylistAttributeGenius  = (1 << 2)
};
typedef NSInteger MPMediaPlaylistAttribute;

I want to log the value to the terminal, so i used

NSLog(@"playlist attribute value:%@", [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] stringValue]);

However, it prints out a value of 0 every time. This means that either every playlist has the attribute "MPMediaPlaylistAttributeNone", but this doesnt make sense since it is going through many genius and on the go playlists as well.

here is my entire code:

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
    NSLog(@"number of playlists total:%d", [[myPlaylistsQuery collections] count]);
    NSArray *playlists = [myPlaylistsQuery collections];

    for (MPMediaPlaylist *playlist in playlists) {

     NSInteger theAttributes;

     theAttributes = [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] integerValue];
     NSLog(@"attribute:%d of playlist:%@", theAttributes, [playlist valueForProperty:MPMediaPlaylistPropertyName]);
    }

and here is the result, when i run the application on my iphone. many of these playlists are in fact genius playlists:

attribute:0 of playlist:Purchased

attribute:0 of playlist:Purchased on My iPhone

attribute:0 of playlist:Army of Them

attribute:0 of playlist:Blue

attribute:0 of playlist:Closer

attribute:0 of playlist:Crazy

attribute:0 of playlist:Mad About You

attribute:0 of playlist:Midnight

attribute:0 of playlist:Something Elephants

attribute:0 of playlist:Supermassive Black Hole

attribute:0 of playlist:Take Me Away

attribute:0 of playlist:The Mixed Tape

attribute:0 of playlist:Time

attribute:0 of playlist:All Around Me

attribute:0 of playlist:anna's cd

attribute:0 of playlist:Av

attribute:0 of playlist:av 2

attribute:0 of playlist:Believe

attribute:0 of playlist:BH

attribute:0 of playlist:Boulevard of Broken Dreams

attribute:0 of playlist:car 1

attribute:0 of playlist:car 2

attribute:0 of playlist:car 3

Any ideas why every playlist is coming out as having 0 for the attributes?

Again, thanks for your time!

A: 

Unlike an NSNumber, a NSInteger isn't an object, so you want to use %d instead of %@ to print it out....

David Maymudes
A: 

An NSInteger is just a primitive typedef:

typedef long NSInteger;

I think it is primarily used to avoid issues between 32bit/64bit processors. Treat it like a regular int, and use %d when passing it into a string formatter. Or just avoid the whole issue and use [val intValue]; which returns a normal int.

Joe V
first of all, thank you for the reply. you are right, and i went back and changed that bit of code. it now reads: NSInteger theAttributes; theAttributes = [[playlist valueForProperty:MPMediaPlaylistPropertyPlaylistAttributes] integerValue]; NSLog(@"attribute:%d of playlist:%@", theAttributes, [playlist valueForProperty:MPMediaPlaylistPropertyName]);But, the result is still the same, and each playlist has an attribute of "0". Do I need to get the NSInteger in a different way, or is MPMediaPlaylistPropertyPlaylistAttributes not really supported by the iphone 3.0 SDK?thanks!
A: 

for (MPMediaPlaylist *playlist in playlists) {

    NSInteger theAttributes =[playlist items].count;

    NSLog(@"attribute:%d of playlist:%@", theAttributes, [playlist alueForProperty:MPMediaPlaylistPropertyName]);
};
ArthurBZhou