1

I am currently looking at Apple's AddMusic example and playing around with it before I start rewriting it into my application.

I noticed that it makes its own little playlist of the songs qued. I want to use the swipe action on the table view to remove songs that a use clicked by mistake.

I have implemented the swipe action but can't work out a way to delete that specific row?

Any idea would be great, below is the code to add it. I tried doing the reverse with no luck. If it's not possible how should I go about it?

Cheers

MainViewController *mainViewController = (MainViewController *) self.delegate;
MPMediaItemCollection *currentQueue = mainViewController.userMediaItemCollection;
MPMediaItem *anItem = (MPMediaItem *)[currentQueue.items objectAtIndex: row];
benRollag
  • 1,219
  • 4
  • 16
  • 21
Dan
  • 11
  • 3

1 Answers1

4

An MPMediaItemCollection is immutable, ie. you can't change the items. You need to create a new one with all items less the one you want to remove. See below:

NSArray* items = [currentQueue items];
NSMutableArray* array = [NSMutableArray arrayWithCapacity:[items count]];
[array addObjectsFromArray:items];
[array removeObjectAtIndex:row];
MPMediaItemCollection* newCollection = [MPMediaItemCollection collectionWithItems:array];

Be careful to not create an empty collection. It's not allowed and the MPMediaItemCollection will raise an exception.

hktegner
  • 558
  • 4
  • 9