iPhone SDK,保存MPMediaItemCollection吗? [英] iPhone sdk, save MPMediaItemCollection?

查看:87
本文介绍了iPhone SDK,保存MPMediaItemCollection吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序显示MPMediaPickerController.我想保存MediaItem并在启动时再次播放它.我认为使用MPMediaQuery这是可行的.看来,我应该使用MPMediaItemPropertyPersistentID,但是我不确定如何查询它.有什么想法吗?

I have my application displaying a MPMediaPickerController. I would like to save the MediaItem and start it playing again on startup. I think this is doable using the MPMediaQuery. It seems, I should be using the MPMediaItemPropertyPersistentID but I am not sure how to query for it. Any thoughts?

推荐答案

伙计,您不需要保存mediaCollection.媒体集合只是MPMediaItem对象的数组.因此,您最好保存这些项目的persistentIds.很简单

Man, you dont need to save mediaCollection. media collection it is just array of MPMediaItem objects. So you'd better save persistentIds of this items. it's quite easy

//it's how to know persistentId of the song after you got mediaItemCollection from your mediaPickerViewController
//then you can sav it in userDefaults.
- (NSNumber *)getPersistentId :(MPMediaItemCollection *)collection atIndex:(int)index {
 MPMediaItem *mediaItem = [collection.items objectAtIndex:index];
 NSNumber *anId = [mediaItem valueForProperty:MPMediaItemPropertyPersistentID];
 return anId;
}

//when your application will be launched next time you can get required song:
- (void)obtainSongWitId:(NSNumber *)persistentId {
 MPMediaQuery *query = [MPMediaQuery songsQuery];
 MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:persistentId forProperty:MPMediaItemPropertyPersistentID];
 [query addFilterPredicate:predicate];
 NSArray *mediaItems = [query items];
 //this array will consist of song with given persistentId. add it to collection and play it
 MPMediaItemCollection *col = [[MPMediaItemCollection alloc] initWithItems:mediaItems];
 ///....
 [col release];
}

这篇关于iPhone SDK,保存MPMediaItemCollection吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆