How to receive AVMetricEvent performance data?

I am would like to look at AVMetricEvent data during video playback, so I have added this code to a test video player app:

    let playerItem: AVPlayerItem = ...
    let allMetrics = playerItem.allMetrics()
    Task.init {
        print("metrics task started")
        do {
            for try await metricEvent in allMetrics {
                print("metric event: \(metricEvent.description)")
            }
        } catch {
            print("unexpected metric iterator error \(error)")
        }
    }

Running this in Simulator on iPhone 16 Pro (18.0) does not result in any "metric event" diagnostic messages being printed when the video associated with this AVPlayerItem is playing. Only the "metric task started" diagnostic message is seen.

What am I doing wrong that prevents metric data being received?

It occurred to me that the AsyncIterator we get via allMetrics() might simply not produce any items.

I added an extra diagnostic message just after the for-loop in the above code, and that message is also never displayed - so it seems like the iterator does wait indefinitely for metrics to be produced, as I was expecting.

    let playerItem: AVPlayerItem = ...
    let allMetrics = playerItem.allMetrics()
    Task.init {
        print("metrics task started") // appears in output
        do {
            for try await metricEvent in allMetrics {
                print("metric event: \(metricEvent.description)"). // does not appear
            }
            print("metrics task done") // also does not appear
        } catch {
            print("unexpected metric iterator error \(error)")
        }
    }

Don't know what to try next to get access to this data.

How to receive AVMetricEvent performance data?
 
 
Q