开发者

Playing from iPod music library

开发者 https://www.devze.com 2022-12-24 14:52 出处:网络
I want to play particular selected song from my ipod music library.Ho开发者_如何学JAVAw can i do that?

I want to play particular selected song from my ipod music library.Ho开发者_如何学JAVAw 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.


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.

0

精彩评论

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

关注公众号