gpt4 book ai didi

iPhone sdk,保存MPMediaItemCollection吗?

转载 作者:行者123 更新时间:2023-12-03 18:41:31 24 4
gpt4 key购买 nike

我的应用程序显示 MPMediaPickerController。我想保存 MediaItem 并在启动时再次播放。我认为使用 MPMediaQuery 可以做到这一点。看来,我应该使用 MPMediaItemPropertyPercientID 但我不知道如何查询它。有什么想法吗?

最佳答案

伙计,你不需要保存 mediaCollection。媒体集合它只是 MPMediaItem 对象的数组。所以你最好保存这个项目的permanentIds。这很容易

//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吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1745739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com