0

I need to start playing a song (which is in the iPod library) in another iOS App using the name of the song.

I've studied some of the MediaPlayer framework, but didn't find anything useful. I know this can be done, as a couple of apps in the App Store do it, such as SoundHound, which lets you play a certain song you've discovered if you have it in your iPod library.

jscs
  • 63,694
  • 13
  • 151
  • 195
David Pollak
  • 60
  • 1
  • 10

2 Answers2

1

try this : http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-music-library-access/

EDIT:

you can try this to reach songs:

#pragma mark - Media Picker

- (IBAction)showMediaPicker:(id)sender
{
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];

    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = YES;
    mediaPicker.prompt = @"Select songs to play";

    [self presentModalViewController:mediaPicker animated:YES];
    [mediaPicker release];
}

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

        [musicPlayer setQueueWithItemCollection: mediaItemCollection];
        [musicPlayer play];
    }

    [self dismissModalViewControllerAnimated: YES];
}


- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker 
{
    [self dismissModalViewControllerAnimated: YES];
}
relower
  • 1,293
  • 1
  • 10
  • 20
  • 1
    Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – codingbadger Nov 10 '11 at 20:21
0

If you would like to play a song with a specific title, without requiring the user to select the song manually with the Media Picker, you might want to try a Media Player Query using the song title.

MPMediaPropertyPredicate *titlePredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
                             forProperty:MPMediaItemPropertyTitle
                             comparisonType:MPMediaPredicateComparisonContains];

NSSet *predicates = [NSSet setWithObjects: titlePredicate, nil];

MPMediaQuery *songsQuery =  [[MPMediaQuery alloc] initWithFilterPredicates: predicates];

NSLog(@"%@", [songsQuery items]);

There is are good code examples and more discussion on queries at MPMediaQuery search for Artists, Albums, and Songs

Community
  • 1
  • 1