Merge pull request #144 from svga/2.5.5

2.5.5
This commit is contained in:
PonyCui
2020-10-14 15:39:56 +08:00
committed by GitHub
5 changed files with 24 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "SVGAPlayer"
s.version = "2.5.4"
s.version = "2.5.5"
s.summary = "SVGAPlayer 是一个高性能的动画播放器"
s.description = <<-DESC
SVGA 是一种全新的动画格式,由 YY UED 团队主导开发;

View File

@@ -50,6 +50,7 @@ static SVGAParser *parser;
@"https://github.com/yyued/SVGA-Samples/blob/master/rose.svga?raw=true",
];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// parser.enabledMemoryCache = YES;
[parser parseWithURL:[NSURL URLWithString:items[arc4random() % items.count]]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
@@ -66,6 +67,8 @@ static SVGAParser *parser;
NSParagraphStyleAttributeName: para,
}];
[self.aPlayer setAttributedText:str forKey:@"banner"];
// self.aPlayer.mianRunLoopMode = NSDefaultRunLoopMode;
[self.aPlayer startAnimation];
}
} failureBlock:nil];

View File

@@ -28,6 +28,7 @@ typedef void(^SVGAPlayerDynamicDrawingBlock)(CALayer *contentLayer, NSInteger fr
@property (nonatomic, assign) IBInspectable int loops;
@property (nonatomic, assign) IBInspectable BOOL clearsAfterStop;
@property (nonatomic, copy) NSString *fillMode;
@property (nonatomic, copy) NSRunLoopMode mainRunLoopMode;
- (void)startAnimation;
- (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse;

View File

@@ -84,7 +84,7 @@
}
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)];
self.displayLink.frameInterval = 60 / self.videoItem.FPS;
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.mainRunLoopMode];
self.forwardAnimating = !self.reversing;
}
@@ -156,7 +156,7 @@
}
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)];
self.displayLink.frameInterval = 60 / self.videoItem.FPS;
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.mainRunLoopMode];
}
}
@@ -523,4 +523,11 @@
return _dynamicDrawings;
}
- (NSRunLoopMode)mainRunLoopMode {
if (!_mainRunLoopMode) {
_mainRunLoopMode = NSRunLoopCommonModes;
}
return _mainRunLoopMode;
}
@end

View File

@@ -32,6 +32,7 @@
static NSCache *videoCache;
static NSMapTable * weakCache;
static dispatch_semaphore_t videoSemaphore;
+ (void)load {
static dispatch_once_t onceToken;
@@ -40,6 +41,7 @@ static NSMapTable * weakCache;
weakCache = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory
valueOptions:NSPointerFunctionsWeakMemory
capacity:64];
videoSemaphore = dispatch_semaphore_create(1);
});
}
@@ -209,19 +211,26 @@ static NSMapTable * weakCache;
}
+ (SVGAVideoEntity *)readCache:(NSString *)cacheKey {
dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER);
SVGAVideoEntity * object = [videoCache objectForKey:cacheKey];
if (!object) {
object = [weakCache objectForKey:cacheKey];
}
return object;
dispatch_semaphore_signal(videoSemaphore);
return object;
}
- (void)saveCache:(NSString *)cacheKey {
dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER);
[videoCache setObject:self forKey:cacheKey];
dispatch_semaphore_signal(videoSemaphore);
}
- (void)saveWeakCache:(NSString *)cacheKey {
dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER);
[weakCache setObject:self forKey:cacheKey];
dispatch_semaphore_signal(videoSemaphore);
}
@end