Skip to content

Instantly share code, notes, and snippets.

@k06a
Last active September 7, 2023 11:51
Show Gist options
  • Save k06a/a279cdf0d479c4df2d05377ab3681788 to your computer and use it in GitHub Desktop.
Save k06a/a279cdf0d479c4df2d05377ab3681788 to your computer and use it in GitHub Desktop.
Smooth AVPlayer scrolling in UICollectionView/UITableView
#import <JRSwizzle/JRSwizzle.h>
@implementation AVPlayerItem (MLWPerformance)
+ (void)load {
[AVPlayerItem jr_swizzleMethod:NSSelectorFromString(@"_attachToFigPlayer") withMethod:@selector(mlw_attachToFigPlayer) error:nil];
}
- (void)mlw_attachToFigPlayer {
static dispatch_queue_t queue = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
});
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
@weakify(self);
dispatch_async(queue, ^{
@strongify(self);
[self mlw_attachToFigPlayer];
dispatch_group_leave(group);
});
while (dispatch_group_wait(group, DISPATCH_TIME_NOW)) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment