3

I am trying to do the stack overflow claimed impossible task of achieving ~60fps scroll performance in a collection view which contains some videos here and there (auto-playing). I have spent months on this and attempted every solution presented online and have gotten very very close. Creating the asset on a background thread and adding to the view is fine and having it auto play is all great, I can do that without any hiccups in performance.

The ONLY issue I have is that over time I build up a lot of instances of the player (even tho I am reusing the player and playerLayer in my cells...

player threads

Now this is fine for a while until the user has seen many videos and then eventually the videos just stop playing, obviously as there are so many instances active. To stop this build-up I need to remove the playerLayer from the superview every time, or replace the media item (which we all know runs on main thread and makes this task impossible).

SO, my question is, is there ANY OTHER WAY to kill off these old threads? If so, I will have finally found a solution to smooth scrolling with AVPlayer and I can return the favor to the community and post all my code!

Gregg
  • 1,477
  • 1
  • 16
  • 17
  • Hi @Gregg, why do you need to create _a lot of instances of the player_? – kanobius Apr 20 '16 at 01:55
  • I work for a company that wants a collection view of videos/photos. so there could be as many as 5 or 6 videos playing at once in a collection view with hundreds more below as you scroll. – Gregg Apr 25 '16 at 15:02
  • So, _a lot_ is 5 or 6 instances and a few more for reusing, 10 or 12 as max I suppose, right? – kanobius Apr 25 '16 at 15:43
  • Did you every figure this out Gregg? I may be able to help you with this. – user3344977 May 17 '16 at 03:27
  • Yes we were able to fake it by disposing of the avplayer instances when the user stops scrolling. It's not perfect but it works. I'm almost certain the way AVPlayer blocks the main thread currently there is anyway to do it without a UI hiccup short of building your own media player at the gl level – Gregg May 19 '16 at 16:25
  • I am trying to achieve the same, I stopped all players in **tableView: UITableView, didEndDisplaying** Method and it's being stopped, but the problem of threads is still exists. Many threads keeps on running, Did you found the way to clear them? @Gregg – Bhavin Kansagara Jun 30 '17 at 09:10
  • 1
    @BhavinKansagara see my response here: https://stackoverflow.com/questions/30363502/maintaining-good-scroll-performance-when-using-avplayer/35961765#35961765 – Gregg Jul 02 '17 at 20:32

0 Answers0