Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mitchellporter/50b5de12f9aa218adfc3 to your computer and use it in GitHub Desktop.

Select an option

Save mitchellporter/50b5de12f9aa218adfc3 to your computer and use it in GitHub Desktop.
// the cell creation logic
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UVLVideoCell *videoCell = (UVLVideoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UVLVideoCell class]) forIndexPath:indexPath];
NSInteger index = 1 + indexPath.item%2;
NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"flak_0%i", index] withExtension:@"mp4" subdirectory:@"videos"];
[videoCell loadVideoURL:sampleURL];
return videoCell;
}
// inside the cell
- (void)loadVideoURL:(NSURL *)url
{
self.gpuMovie = [[GPUImageMovie alloc] initWithURL:url];
self.gpuMovie.shouldRepeat = YES;
[self.gpuMovie addTarget:self.gpuView];
[self.gpuMovie startProcessing];
}
// called when cell goes off-screen
- (void)didEndDisplayingCell
{
[self.gpuMovie cancelProcessing];
self.gpuMovie = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment