如何使用UICollectionview播放Facebook风格的视频 [英] How to play Facebook style video using UICollectionview
问题描述
我正在尝试使用 ZOWVideoPlayer c> c>在 UICollectionview
单元格中播放视频一> 即可。视频播放效果很好,但目前我的 collectionview 正在播放所有可见视频。我想只播放一个完全可见的视频。这意味着当前视频没有通过滚动过程裁剪(像素不在屏幕外,但完全可见)。
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).
我还添加了代码来检查完整的可见单元格在 scrollview 委托方法中,然后我的 collectionview 会卡住1或2秒然后移动,所以请帮帮我。
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.
请先阅读问题,然后进行投票。
以下是检查可见单元格的代码
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 - >您可以添加用于存储玩家当前状态的枚举
isPlaying -> An enum you can add for storing player current state
希望这是有道理的;)
这篇关于如何使用UICollectionview播放Facebook风格的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!