Jitendra
Jitendra

Reputation: 5081

Set Thumbanail mp3 Song Thumbnail image to my imageView

I want to set my MP3 song thumbnail image to my Imageview;

i have an song array that contains 5 songs. i want to set the first song thumbnail to my Imageview.

my array is this

mp3Array=[[NSArray alloc]initWithObjects:@"song",@"song1",@"song2",@"song3",@"song4", nil];

Crash at this line

MPMediaItemArtwork *itemArtwork = [song valueForProperty:
                                       MPMediaItemPropertyArtwork];

Crash log is

erminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString valueForProperty:]: unrecognized selector sent to instance 0x8dd0

I tried this code to set thumbnail but not set thumbnail crash the app.

code is below...

  MPMediaItem * song=[mp3Array objectAtIndex:delegate.count];

    UIImage *image = nil;

    MPMediaItemArtwork *itemArtwork = [song valueForProperty:
                                       MPMediaItemPropertyArtwork];
    if(itemArtwork != nil)

        image = [itemArtwork imageWithSize:CGSizeMake(100,100)];

[imgView setImage:image];

where may i wrong.

help me out this...

thanks in advance..

Upvotes: 1

Views: 495

Answers (2)

Michael Dautermann
Michael Dautermann

Reputation: 89539

Okay. Here is your problem: your array appears to have NSString objects in them:

mp3Array=[[NSArray alloc]initWithObjects:@"song",@"song1",@"song2",@"song3",@"song4", nil];

These need to be MPMediaItem objects if you want to be able to retrieve MPMediaItem objects and not NSString objects from the array.

Upvotes: 1

Martijn
Martijn

Reputation: 470

If you declare UIImage *image = nil;, then there is no ivar image. Replace that line with UIImage *image = [[UIImage alloc] init];. Because of that, you will be able to set the image with imagewithSize after the if-statement.

Upvotes: 0

Related Questions