How do I clear the queue of a MPMusicPlayerController?
Asked Answered
P

1

5

I'm trying to replicate the clear queue functionality of the iPod application, however I can't create an empty MPMediaItemCollection with which to call setQueueWithItemCollection:

e.g.

[self.musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:[NSArray array]]];

where musicPlayer is a MPMusicPlayerController.

throws an exception:

*** Terminating app due to uncaught exception 'MPMediaItemCollectionInitException', reason: 'items array must not be empty'

Is there a way to clear a MPMusicPLayerController queue that avoids this problem?

Any help is greatly appreciated, CV

Perennial answered 17/6, 2010 at 6:2 Comment(0)
S
9

I don't know if you've managed to overcome your problem, but here's a workaround that seems to be working for me.

MPMediaPropertyPredicate *predicate =
    [MPMediaPropertyPredicate predicateWithValue: @"Non_Existant_Song_Name"
                                     forProperty: MPMediaItemPropertyTitle];
MPMediaQuery *q = [[MPMediaQuery alloc] init];
[q addFilterPredicate: predicate];
[self.player.controller setQueueWithQuery:q];
self.player.controller.nowPlayingItem = nil;
[self.player.controller stop];

This basically sets the play queue up with a query that you're sure will never turn up any songs. Ideally a query that's really quick to perform. And then it nullifies the nowPlayingItem and then for good measure tells the player to stop.

Hope that helps.

Sectionalism answered 21/11, 2010 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.