Search code examples
iosswiftavplayeravplayerlayer

UICollectionView & AVPlayer Performance


I have a UICollectionView whose cells each have an AVPlayerLayer, all playing a video at the same time. About 9 cells fit on the screen at a time and it's pretty laggy so I need ways to boost the performance to achieve smooth scroll. There's a few things I've tried already:

1) Each cell has only one instance of AVPlayer. It doesn't get created, instead, player.replaceCurrentItemWithPlayer is called when the video url changes.

2) Because I'm using ReactiveCocoa, it's trivial to skip repeat urls to avoid playing the same video twice.

What else can I do to speed up the scroll and performance?


Solution

  • First I want to say it's a bit crazy to see several players in action at the same time: it's a heavy task of rendering anyway.

    As far as I know, simply scaling/re-framing the video to smaller size doesn't make it less content to render: if you have a 100x100 picture to render and you render it in a frame of 10x10, it still consumes the same amount of memory as the original picture would consume; same thing goes for videos. So, try to make your video assets having similar resolution as the frame where you would present them.