我希望我的代码允许我通过我的ipod库选择多个项目。目前我可以选择一首歌。我想修改我的代码,以便将一系列歌曲添加到曲目中。当前为“选择多个项目”选择“是”允许选择,但是回放仅包括一首歌曲。第一个被选中。
我怎么能改变这个。我在下面列出了我的代码示例......
@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
答案 0 :(得分:1)
而不是
NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];
选择第一首歌
试
if (mediaItemCollection)
[musicPlayer setQueueWithItemCollection: mediaItemCollection];