Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play Facebook style video using UICollectionview

I am attempting to play video in UICollectionview Cell using ZOWVideoPlayer. Video is playing perfectly but currently my collectionview is playing all visible videos. I want to play only single completely visible video. This means the current video that is not cropped by scrolling process (pixels are not off-screen, but fully visible).

I also added code to check the complete visible cell in scrollview delegate methods but then my collectionview gets stuck for 1 or 2 seconds and then moves, so please help me out.

And Please Read question first then make Down vote.

Here is the code for check visible cell

- (void)checkVisibilityOfCell:(CustomCell *)cell inScrollView:(UIScrollView *)aScrollView {
    @try {
        CGRect cellRect = [aScrollView convertRect:cell.frame toView:aScrollView.superview];
        if (cell.videoPlayer) {
            if (CGRectContainsRect(aScrollView.frame, cellRect)){
                //Play Video
            }
            else{
                //Pause Video
            }
        }
    } @catch (NSException *exception) {

    } @finally {

    }
}
like image 915
Hardik Kardani Avatar asked Aug 11 '16 05:08

Hardik Kardani


1 Answers

I suspect your method is getting called more than once. As you are only checking for players existence. Why don't you add another check for the player state? So if the player is playing, just ignore it.

if (CGRectContainsRect(aScrollView.frame, cellRect) && !isPlaying) {

isPlaying -> An enum you can add for storing player current state

Hope this make sense ;)

like image 167
Mahesh Verma Avatar answered Sep 21 '22 07:09

Mahesh Verma