Tôi muốn để có được những album nghệ thuật từ một audiobook trong thư viện iPod, Nhưng tôi không hiểu làm thế nào để sử dụng MPMediaItemPropertyArtwork
iOS: Bắt và hiển thị album ảnh nghệ thuật từ iPod thư viện
- (NSArray *)audiobooks
{
MPMediaPropertyPredicate *abPredicate =
[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInt:MPMediaTypeAudioBook]
forProperty:MPMediaItemPropertyMediaType];
MPMediaQuery *abQuery = [[MPMediaQuery alloc] init];
[abQuery addFilterPredicate:abPredicate];
[abQuery setGroupingType:MPMediaGroupingAlbum];
NSArray *books = [abQuery collections];
return books;
}
- (MPMediaItem *)mediaItemForRow: (NSInteger)row
{
NSArray *audiobooks = self.audiobooks;
MPMediaItem *mediaItem = nil;
for (id object in audiobooks) {
if ([object isKindOfClass:[MPMediaItemCollection class]]) {
MPMediaItemCollection *book = (MPMediaItemCollection *)object;
id item = [book items][row];
if ([item isKindOfClass:[MPMediaItem class]]) {
mediaItem = (MPMediaItem *)item;
}
}
}
return mediaItem;
}
Vì vậy, bây giờ tôi có thể nhận được danh hiệu của mục phương tiện truyền thông như thế này:
NSString *title = [mediaItem valueForProperty:MPMediaItemPropertyArtist];
Nhưng làm thế nào để tôi có được tác phẩm nghệ thuật để tôi có thể hiển thị nó trong UIImage? có sản phẩm này:
[mediaItem valueForProperty:MPMediaItemPropertyArtwork]
Tôi chưa tìm ra cách sử dụng.
thể trùng lặp của [Không thể nhận được UIImage từ MPMediaItemPropertyArtWork] (http://stackoverflow.com/questions/6604829/not-able-to-get-the-uiimage-from-mpmediaitempropertyartwork) –
đây là một tham chiếu hữu ích: https://stackoverflow.com/questions/28979013/how-do-i-get-the-album-artwork-of-the-currently-playing-music-using-swift/48035857#48035857 –