1

根据 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];
    }
}

有没有其他人看过这个?

4

1 回答 1

0

I can confirm that in my case, on a 4.2.1 iPad, that this property does in fact hold a value. In this screenshot my debugger is sitting on the line in question.

enter image description here

于 2011-09-13T23:55:13.713 回答