Pages

Thursday, March 28, 2013

MediaPlayer

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!


View the original article here

0 comments:

Post a Comment