Playing from iPod music library

I want to play particular selected song from my ipod music library.How can i do that? My idea is to save the title name from MPMediaQuery and then play later on when app starts so any one can have idea to do this?

Thank You.

Answers


The basic solution is to save the unique identifier each song in the library has, aka MPMediaItemPropertyPersistentID. You can use this ID to play the song, and you can save the ID to memory in order to remember the song the user selected between launches. If you don't know how the Media Player Framework works, look at the AddMusic sample code.

Your view controller must implement the MPMediaPickerControllerDelegate protocol. Assuming you're just allowing the user to select a single song, then the basic outline of your callback will look something like this.

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
    NSArray* items = [mediaItemCollection items];
    if ([items count] == 1)
    {
        MPMediaItem* song = (MPMediaItem *)[items objectAtIndex:0];
        NSNumber* persistentId = [song valueForProperty:MPMediaItemPropertyPersistentID];
        // ...Save/Play here...
    }
}

At this point you can use the persistent ID to play the song, and/or save it to user defaults.


Need Your Help

Mathcad 14: "pattern match exception" when solving equation with more unknowns

exception match equation mathcad

I'm trying to solve an equation with 5 unknowns in Mathcad 14. My equations look like this:

Creating text file from as2

flash scripting actionscript-2 text-files

I'm trying to find a way to write to a text file from as2. I don't want to use any php or asp because my app needs to run without an internet connection. As3 has FileReference.save() and judging by...