根据 Apple 文档,AVPlayerItem 的“资产”属性应该可用,并在 iOS 4.0 及更高版本中返回有效对象。我发现在 iOS 4.2 中,AVPlayerItem 对象的“资产”属性始终为零。示例代码:
CMTime theDuration = kCMTimeInvalid;
AVPlayerItem* theItem = anAVPlayer.currentItem;
AVAsset* theAsset = nil;
if ([AVPlayerItem instancesRespondToSelector:@selector(duration)]) {
// On iOS 4.3 we get here...
theDuration = [theItem duration];
} else if ([AVPlayerItem instancesRespondToSelector:@selector(asset)]) {
// On iOS 4.2 we get here...
theAsset = [theItem asset];
if (theAsset) {
// Unfortunately, we do not get here as theAsset is nil...
theDuration = [theAsset duration];
}
}
有没有其他人看过这个?