Issues with "AVMetricEventStreamPublisher Discover Media Performance Metrics in AVFoundation" Example Code

Hi everyone! I’ve been working with AVFoundation and trying to use the AVMetricEventStreamPublisher to discover media performance metrics, as described in the Apple documentation. https://developer.apple.com/cn/videos/play/wwdc2024/10113/?time=508

However, when following the example code, I’m not getting the expected results. The performance metrics for both audio and video don’t seem to be captured properly.

Has anyone successfully used this example code? If so, could you share your experience or any solutions you’ve found? Any tips or insights would be greatly appreciated. Thanks in advance!

Ps. the example code:

AVPlayerItem *item = ...

AVMetricEventStream *eventStream = [AVMetricEventStream eventStream]; id<AVMetricEventStreamSubscriber> subscriber = [[MyMetricSubscriber alloc] init]; [eventStream setSubscriber:subscriber queue:mySerialQueue]

[eventStream subscribeToMetricEvent:[AVMetricPlayerItemLikelyToKeepUpEvent class]]; [eventStream subscribeToMetricEvent:[AVMetricPlayerItemPlaybackSummaryEvent class]];

[eventStream addPublisher:item];

Answered by Systems Engineer in 836296022

Hey there!

Could you elaborate on how the metrics aren't captured properly? Are you seeing no AVMetricEvents at all or are you receiving them but with information different than you expect? And what kind of asset are you using with the example code?

Additionally, if you prefer, feel free to file a FeedbackAssistant form with details about your code and the unexpected behavior you're seeing. https://developer.apple.com/bug-reporting/

Accepted Answer

Hey there!

Could you elaborate on how the metrics aren't captured properly? Are you seeing no AVMetricEvents at all or are you receiving them but with information different than you expect? And what kind of asset are you using with the example code?

Additionally, if you prefer, feel free to file a FeedbackAssistant form with details about your code and the unexpected behavior you're seeing. https://developer.apple.com/bug-reporting/

Issues with "AVMetricEventStreamPublisher Discover Media Performance Metrics in AVFoundation" Example Code
 
 
Q