Monday, August 22, 2016

How to play Facebook style video using UICollectionview

Leave a Comment

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 {      } } 

1 Answers

Answers 1

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 ;)

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment