SRGSSR / pillarbox-apple

A next-generation reactive media playback ecosystem for Apple platforms.
https://testflight.apple.com/join/TS6ngLqf
MIT License
45 stars 6 forks source link

Fix resource loading conflicts with playlist management #81

Closed defagos closed 1 year ago

defagos commented 1 year ago

As a user I want a good user experience with any kind of content.

Acceptance criteria

Hints

A custom resource loader was implemented in #60 to load content from URNs and deque playlist support was added with #76. When combined these two features show several issues:

Remarks:

Tasks

Probably better investigated in a project implemented from scratch. An idea:

defagos commented 1 year ago

Some learnings and checks:

defagos commented 1 year ago

Even though AVAsset.cancelLoading() does not cancel resource loading failing to do so leads to the reported lengthy cleanup time when closing the player while only part of the resources have been loaded (likely because some implicit async property retrieval is still pending). The player is still deallocated early so performing this call in deinit fixes the issue.

Calling AVPlayerItem.cancelPendingSeeks() is likely good practice as well.

defagos commented 1 year ago

SRG Media Player already calls -[AVAsset cancelLoading] so no improvement PR can be made. Remaining issues in Letterbox likely have another cause.

defagos commented 1 year ago

I checked with LLDB (breakpoint + printing $arg4) that AVPlayerItem.init(url:) calls AVPlayerItem.init(asset:automaticallyLoadedAssetKeys:) with ["duration", "availableMediaCharacteristicsWithMediaSelectionOptions"] as automatically loaded asset keys.

If we want to minimize the number of keys automatically loaded before the item is ready to play we should introduce a convenience constructor.

defagos commented 1 year ago

I doubt AVAssetResourceLoadingContentInformationRequest can be filled in a meaningful way, as we are not getting media data, rather only the playlist (provided as a redirect).

defagos commented 1 year ago

Tests work fine if we load items without automaticallyLoadedAssetKeys (checked with a global find & replace; won't be tested automatically since would add only noise).

defagos commented 1 year ago

~Resource loader issues described in this issue are not related to our implementation (according to what I know after investigating the topic further)~

Resource loading issues were ours, see #116, but still there are issues on iOS 16.0 which cannot be our own (automatic item chaining of AVQueuePlayer can struggle to resume playback). So we should bump the minimum OS version later, see #79.