AVPlayerItem duration remains indefinite after status becomes .readyToPlay

Originator:GornostaevaMV
Number:rdar://45672773 Date Originated:October 30 2018
Status:Open Resolved:
Product:iOS SDK Product Version:12
Classification:Other Reproducible:Sometimes
 
Area:
AVFoundation

Summary:

AVPlayerItem's duration value (CMTime) remains indefinite after status of the item becomes .readyToPlay. AVPlayerItem gets correct duration and sends a KVO notification just a moment after status of the item becomes .readyToPlay, but it's not yet available at the moment of status KVO observation.
Reproducible in 1-10% of the cases, and only when running on iOS 12. The issue is reproducible more often on a fast network (100mbps), or with a local file. Reproduces both on device and simulator.

Steps to Reproduce:

1. Initialize an AVPlayerItem with an asset (from the bundle or a remote file)
2. Create an AVPlayer instance with that item and automatically loaded duration key, add KVO observers for "duration" and "status"
3. Let the player be, so it makes itself ready to play.

Expected Results:

When KVO notification arrives for status becoming .readyToPlay, duration is always a valid CMTime value, as mentioned in documentation for AVPlayerItem.duration and in the comment for AVPlayerItem.duration in the header file.

Actual Results:

In some runs, when KVO notification arrives for status becoming .readyToPlay, duration is still indefinite. 

Version/Build:
Simulator: Version 10.0 (SimulatorApp-869.5 CoreSimulator-572.2), tested on iPhone 7 and iPhone XR simulators.
Device: iOS 12.0.1 (16A405), iPhone XS

Configuration:
Xcode Version 10.0 (10A255)

Comments

Potentially the same bug as http://www.openradar.me/20490378

By GornostaevaMV at Oct. 30, 2018, 5:40 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!