Closed defagos closed 2 years ago
The issue arises because of internal changes made by Apple to AVPlayerViewController
implementation in tvOS 15.2.
When playing another media, our current SRGMediaPlayerViewController
implementation first resets the state (setting the player
to nil
first), then prepares playback (setting the player
to a fresh AVPlayer
instance). At the SRGMediaPlayerViewController
level we track player changes with KVO and switch the player view controller player accordingly. Thus, with our current implementation, the AVPlayerViewController
player instance is updated twice in a row when playing another media, the first time to nil
, then to a new instance.
Before tvOS 15 this was not an issue. But since tvOS 15 switching the AVPlayerViewController
player instance several times in a row can lead to crashes, likely because of an incorrect KVO implementation to track interstitials updates. This also means that the crash does not affect SRGMediaPlayerViewController
on iOS, as interstitials are not available on this platform.
We can fix the crash by avoiding unnecessary player changes at SRGMediaPlayerController
level so that KVObservation at SRGMediaPlayerViewController
level minimizes updates as well. This requires two kinds of code changes:
-reset
method so that resetting when switching to another media can be made without unnecessarily transitioning to a nil
player.This issue will be reported to Apple, though in the future we might switch to AVQueuePlayer
. In this case a controller will always have one AVQueuePlayer
instance, which should avoid this kind of problems.
Fix proposal available for review on feature/tvos15-crash-fix
.
Merged into develop
.
I opened a dedicated radar.
When testing my sample code I also discovered that the player associated with AVPlayerViewController
leaks on iOS after an update. The workaround applied for the crash does not help in fixing this issue so it should probably be reported separately to Apple.
As described on Letterbox issue tracker, changing the media currently being played crashes on tvOS 15.2 due to an internal implementation change made by Apple.
Issue type
Crash
Description of the problem
Stack trace:
Environment information
Reproducibility
Always reproducible
Code sample
Add to
MediasViewController~tvos.m
:and call right after
SRGMediaPlayerViewController
presentation:This periodically updates the media being played, which should usually be properly implemented with a custom
AVPlayerViewController
overlay. The above is sufficient to reproduce the issue, though.Steps to reproduce