3 Replies Latest reply: Mar 22, 2013 8:47 AM by etresoft
Neo2000 Level 1 Level 1 (0 points)

I'm trying to make a music player app for iOS and am having some difficulty with MediaPlayer.framework.

Here is some code from my prototype:

- (IBAction)showMediaPicker:(id)sender{

    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];

    mediaPicker.delegate = self;

    mediaPicker.allowsPickingMultipleItems = YES;

    mediaPicker.prompt = @"Select songs to play";

    [self presentViewController:mediaPicker animated:YES completion:nil];



- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection


    if (mediaItemCollection) {

        [musicPlayer setQueueWithItemCollection: mediaItemCollection];

        [musicPlayer play];


    [self dismissViewControllerAnimated:YES completion:nil];


- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker


    [self dismissViewControllerAnimated:YES completion:nil];



musicPlayer is defined as:

In the .h file:

MPMusicPlayerController *musicPlayer;

@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;


This piece of code brings up a view to pick some songs to play. The problem is that if I pick song a and b, listen to a and decide to add song c and d, only c and d play. This means that the songs are not added to the queue, the queue is deleated and songs are added on top of that. This is also a problem because you can't(at least in the code I use)go back to the previous song or go to the next song unless it is in the queue.

How can I add to the queue without the data being deleated.

Also if you know any good documentation or tutorial on MediaPlayer.framework please share it.

I should also point out that i am in the process of learning iOS development so if it is a general problem could you plaese derect to me some documentation or to a tutorial.

Thanks in advance!

OS X Mountain Lion (10.8.2)
  • 1. Re: MediaPlayer
    etresoft Level 7 Level 7 (24,270 points)

    setQueueWithItemCollection sets a new queue using a new collection. You need to create a collection containing your previous queue and the new entries.

  • 2. Re: MediaPlayer
    Neo2000 Level 1 Level 1 (0 points)

    Sorry but as I stated I am new to iOS programming and am self taught. I am learning iOS development using these projects I come up with. I understand what you are saying but I do not know how to implement it in code so could you please explain to me how to do this.

    Thanks a lot for tha help! I believe you've helped me before as we'll.

  • 3. Re: MediaPlayer
    etresoft Level 7 Level 7 (24,270 points)

    I suggest taking some programming classes at a local college or university. They don't actually teach programming very well, but that is all there is right now. In order to use the tools available and assemble all the pieces, you need to know how to use those tools and recognize which pieces go where.