'NSInvalidArgumentException', reason: '

2019-08-18 20:30发布

问题:

I am trying to play a MediaItem using AVPlayer and later trying to get the duration of the current item like this (duration is an object of type CMTime):

duration = [[player currentItem] duration];

I get no issues in iPad but in iPod Touch, I get the following error. I haven't tried this in iPhone yet.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVPlayerItem duration]: unrecognized selector sent to instance 0x186100'

Any pointers to the fix will be greatly appreciated.

回答1:

You're most likely testing this on an iPod with iOS < 4.3.

According to the AVPlayerItem documentation, duration is only available in iOS 4.3 or later.