我已经更新到最新的XCode,两台设备上的最新iOS以及iTunes.我已经在iPad 4,iPad Air,iPhone 5,iPhone 6上进行了测试.希望有人知道发生了什么,它现在似乎是iOS 8中的一个已知错误.此外,我可以播放资产并检索歌曲名称和艺术家等内容.
MPMediaquery *songquery = [MPMediaquery songsquery];NSArray *itemsFromGenericquery = [songquery items];NSMutableArray *songsList = [[NSMutableArray alloc] initWithArray:itemsFromGenericquery];MPMediaItem *mediaItem = (MPMediaItem *)[songsList objectAtIndex:0];NSURL *url = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];AVAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];NSArray *commonArray = [assets commonMetadata];//Test ANSArray *albumArray = [AVMetadataItem MetadataItemsFromArray:commonArray filteredByIDentifIEr:AVMetadataIDentifIEriTunesMetadataCoverArt];NSLog(@"commonArray = %lu",(unsigned long)[commonArray count]); //Returns 3NSLog(@"albumArray has %lu",(unsigned long)[albumArray count]); //Returns 0 or null//Test Bfor (AVMetadataItem *MetadataItem in asset.commonMetadata) { if ([MetadataItem.commonKey isEqualToString:@"artwork"]){ NSDictionary *imageDataDictionary = (NSDictionary *)MetadataItem.value; NSData *imageData = [imageDataDictionary objectForKey:@"data"]; UIImage *image = [UIImage imageWithData:imageData]; coverArtimage.image = image; }}//Test Cfor (AVMetadataItem *item in commonArray) { if ([item.keySpace isEqualToString:AVMetadataKeySpaceiTunes]) { NSData *newImage = [item.value copyWithZone:nil]; coverArtimage.image = [UIImage imageWithData:newImage]; }}//Test Dfor (AVMetadataItem *item in asset.Metadata) { if ([item.commonKey isEqualToString:@"artwork"]){ NSDictionary *imageDataDictionary = (NSDictionary *)item.value; NSData *imageData = [imageDataDictionary objectForKey:@"data"]; UIImage *image = [UIImage imageWithData:imageData]; coverArtimage.image = image; } if ([item.keySpace isEqualToString:AVMetadataKeySpaceiTunes]) { NSData *newImage = [item.value copyWithZone:nil]; coverArtimage.image = [UIImage imageWithData:newImage]; }}
所有封面艺术图像返回null或永远不会被调用.此外,苹果建议从直接文件中提取封面艺术是异步的,但无论我尝试使用哪种设备,似乎至少需要10秒钟. iOS 7允许我们直接从mediaItem中提取封面艺术并且它是瞬间的,我不明白为什么他们会对这个功能产生负面影响.
解决方法Nsstring *queryString = [url query];if (queryString == nil) // shouldn't happen return nil;NSArray *components = [queryString componentsSeparatedByString:@"="];if ([components count] < 2) // also shouldn't happen return nil;ID trackID = [components objectAtIndex:1];MPMediaquery *query = [[MPMediaquery alloc] init];[query addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:trackID forProperty:MPMediaItemPropertyPersistentID]];NSArray *items = [query items];[query release];if ([items count] < 1) // still shouldn't happen return nil;MPMediaItem* mpitem= [items objectAtIndex:0];MPMediaItemArtwork* mpArt = [mpitem valueForProperty:MPMediaItemPropertyArtwork];UIImage* mpImage = [mpArt imageWithSize:mpArt.bounds.size];总结
以上是内存溢出为你收集整理的ios8 – iOS 8专辑封面全部内容,希望文章能够帮你解决ios8 – iOS 8专辑封面所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)