开发者

Media picker item selection

i want my code to allow me to pick multiple items via my ipod library. Currently I am able to select one song. i want to modify my code to allow for a series of songs to be added to the que. Currently selecting YES for "pick multiple items" allows for selection however playback consists of only one song. the first selected.

How may I change this. I have included a sample of my code below...

@implementation ProjectViewController


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{
    [self performSelector:@selector(presentLibrary) withObject:nil afterDelay:0.1];
    [super viewDidLoad];

}

-(void)presentLibrary
{
    MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
    // picker.navigationController.delegate = self;
    picker开发者_开发知识库.delegate = self;
    picker.allowsPickingMultipleItems = YES;
    picker.prompt  = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
    //[self.view addSubview:picker.view];
    [self presentModalViewController: picker animated: YES];
    //picker.view.frame = CGRectMake(picker.view.frame.origin.x, 0, picker.view.frame.size.width, picker.view.frame.size.height);
    [picker release];

}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/



- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;    



}




- (void)dealloc {
    [super dealloc];
}


- (IBAction)onlaunch:(id)sender
{
    xxxxxxxx ViewController *viewController = [[xxxxxxxxxViewController alloc] init];
    [self presentModalViewController:viewController animated:YES];
    [viewController release];
}

-(void)viewDidAppear:(BOOL)animated
{

}


- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
    [self dismissModalViewControllerAnimated: NO];
    //[mediaPicker.view removeFromSuperview];
    //NSURL *url = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"screen1.mp4"]]; //test.caf
    NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];
    NSLog(@"url:%@",url);
    [[ShareInfo shareduserInfoManager] setSongUrl:url];
    [self goToxxxxxxxxxyView];
}

- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker
{
    [self dismissModalViewControllerAnimated: NO];
    [[ShareInfo shareduserInfoManager] setSongUrl:nil];
    [self goToxxxxxxxxxView];
}

-(void)goToxxxxxxxView
{
    xxxxxxxxxxxxxx *viewController = [[xxxxxxxxxxxxxxxr alloc] init];
    [self presentModalViewController:viewController animated:YES];
    [viewController release];
}
@end


Instead of

NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];

Which is selecting the 1st song,

try

if (mediaItemCollection)
    [musicPlayer setQueueWithItemCollection: mediaItemCollection];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜