I'm using AVPlayerViewController
to play back a remote video asset. It works when I use presentViewController: animated: completion:
to pop up the controller.
But it stopped working when I embed AVPlayerViewController
in a UIView
as following:
[avPlayer play];
[videoView addSubview:playerController.view];
playController.view.frame = videoView.bounds;
I also tried to move [avPlayer play]
after the view frame setting, did not work either. The view shows a black background with a play button in the middle. (See attached screenshot).
In more details, I use a delegate to handle the video asset reading via AVAssetResourceLoader setDelegate: queue:
, the logs of the delegate shows that when embedding the AVPlayerViewController, the player did read the video URL a few times (4 requests) but then stopped for apparent no reason.
By a request
, I mean the following callback was called:
resourceLoader:shouldWaitForLoadingOfRequestedResource:
In the failed case, the last request tries to read the last part of the video even though it has not read the previous parts yet:
<AVAssetResourceLoadingDataRequest: 0x60000163be40, requested offset = 8842658, requested length = 4156, requests all data to end of resource = YES, current offset = 8842658>>
In contrast, when using presentViewController
to play back successfully, the last request was reading a much larger length of the video till the end.
<AVAssetResourceLoadingDataRequest: 0x6000005b4620, requested offset = 15884, requested length = 8765940, requests all data to end of resource = NO, current offset = 15884>>
Is there any known issue with embedding AVPlayerViewController
in a UIView? especially when using custom delegate to handle URL asset read?
Thanks!