【问题标题】:commonMetadata array empty for some songs from iPod library来自 iPod 库的某些歌曲的 commonMetadata 数组为空
【发布时间】: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 返回一个空数组?

【问题讨论】:

  • 不,很遗憾没有。如果您找到解决方案,请分享。

标签: iphone avasset


【解决方案1】:

我在下载 m4b 音频文件时遇到了同样的问题。结果证明 AVURLAsset 要求 URL 字符串以“.m4b”结尾(我怀疑其他音频扩展也可以)。如果 URL 类似于 http://source.com/download.php?id=12345,则不能按原样使用 URL。否则,asset.commonMetaData 只会返回一个空数组。我不知道这是否是 iTunes 资产 URL 的问题,但很容易检查。

【讨论】:

    【解决方案2】:

    唯一对我有用的解决方案:

    使用AudioToolbox.framework 从此类文件中检索元数据,即使用AudioFileGetProperty 函数。

    这似乎是AVFoundation 中的一个真正的错误......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多