Closed defagos closed 1 year ago
Some learnings and checks:
AVAsset.cancelLoading()
does not cancel resource loading but only asynchronous property loading.AVPlayerItem.init(asset:)
is to be expected, as the default behavior without automaticallyLoadedAssetKeys
parameter is to wait until the duration is known. Using AVPlayerItem.init(asset:automaticallyLoadedAssetKeys:)
with better parameters (or none) is therefore key to ensure fast startup, especially since we can use property publishers to observe each required property in a very simple way anyway.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.
SRG Media Player already calls -[AVAsset cancelLoading]
so no improvement PR can be made. Remaining issues in Letterbox likely have another cause.
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.
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).
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).
~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.
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:
automaticallyLoadedAssetKeys
set to["playable"]
makes the player start early but, if the player is closed while some items are still not loaded, the player continues to play in the background until all pending resource loader requests have been processed.Remarks:
Tasks
Probably better investigated in a project implemented from scratch. An idea:
automaticallyLoadedAssetKeys
is empty.AVAssetResourceLoadingContentInformationRequest
can be meaningfully filled.