【发布时间】:2013-03-29 12:06:17
【问题描述】:
我正在使用MPMediaPickerController 使用户能够从设备的 iPod 库中挑选歌曲。然后我将这些歌曲放入一个数组中(在本例中为playerQueue)并使用AVPlayer 实例来播放一首又一首的歌曲:
- (void)setQueueWithItemCollection:(MPMediaItemCollection *)theCollection {
for (MPMediaItem *theMediaItem in theCollection.items) {
NSURL *mediaURL = [theMediaItem valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *thePlayerItem = [AVPlayerItem playerItemWithURL:mediaURL];
// Don't add protected tracks to queue as they cannot be played
if (!thePlayerItem.asset.hasProtectedContent && thePlayerItem.asset.isPlayable) [self.playerQueue addObject:thePlayerItem];
// Further implementation
}
}
现在我使用此代码 sn-p(使用 AVPlayer *musicPlayer)获得歌曲标题:
AVPlayerItem *currentItem = self.musicPlayer.currentItem;
AVAsset *asset = currentItem.asset;
// Further implementation
NSLog(@"DEBUG: Meta data: %@", asset.commonMetadata);
NSArray *titles = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
大多数时候这都没有问题。但也有asset.commonMetadata 返回空数组的歌曲。但是,我 iPhone 上的音乐应用程序能够像 iTunes(在 Mac 上)一样显示歌曲标题(和专辑封面等)。
歌曲文件是从 iTunes Store 购买的 Apple MPEG 4 Audio 文件。
即使有可用的元数据,为什么asset.commonMetadata 返回一个空数组?
【问题讨论】:
-
不,很遗憾没有。如果您找到解决方案,请分享。