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 {
}
}
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With