How to stop video playing in YTPlayerView inside UICollectionViewCell when scrolled?
<p>I am using <code>YTPlayerView</code> inside <code>UICollectionView</code>(Horizontal scroll) with one item visible at a time on the screen. I have added a <code>UIView</code> inside custom cell and changed the class name to <code>YTPlayerView</code> in Identity inspector. </p>

<p>For <code>YTPlayerView</code> I have enabled AutoPlay and it is playing well. But, when I scroll to next or previous item I want to stop the player. I tried stopping the player in 'didEndDisplayingCell' by getting custom cell object with <code>NSIndexPath</code>. But <code>YTPlayerView</code> instance with custom cell object returns (null) in 'didEndDisplayingCell'. So I am not able to stop video play. How can I stop video play when scroll to next / prev item?</p>

<p>And I have 3 different custom <code>UICollectionView</code> cells to display text, images and videos (YTPlayerView or AVPlayer).</p>

<p><strong>EDIT</strong>
I tried to get the custom video cell object in 'cellForItemAtIndexPath' by saving previous visible cell indexpath. And I am able to get the custom cell object, but when I try to get the instance of <code>YTPlayerView</code> it is returning new object for <code>YTPlayerView</code>.</p>

<p>Can anyone suggest me the right way to handle youtube videos in <code>UICollectionView</code>.</p>