How to play Facebook style video using UICollectionview

假如想象 提交于 2019-12-05 14:25:28

问题


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:


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



来源:https://stackoverflow.com/questions/38888218/how-to-play-facebook-style-video-using-uicollectionview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!