Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #144 from svga/2.5.5
Browse files Browse the repository at this point in the history
2.5.5
  • Loading branch information
PonyCui authored Oct 14, 2020
2 parents f870676 + 2e3f3c8 commit 5b3e530
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SVGAPlayer.podspec
Original file line number Diff line number Diff line change
@@ -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 团队主导开发;
Expand Down
3 changes: 3 additions & 0 deletions SVGAPlayer/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ - (IBAction)onChange:(id)sender {
@"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;
Expand All @@ -66,6 +67,8 @@ - (IBAction)onChange:(id)sender {
NSParagraphStyleAttributeName: para,
}];
[self.aPlayer setAttributedText:str forKey:@"banner"];

// self.aPlayer.mianRunLoopMode = NSDefaultRunLoopMode;
[self.aPlayer startAnimation];
}
} failureBlock:nil];
Expand Down
1 change: 1 addition & 0 deletions Source/SVGAPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions Source/SVGAPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (void)startAnimation {
}
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;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ - (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay {
}
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];
}
}

Expand Down Expand Up @@ -523,4 +523,11 @@ - (NSDictionary *)dynamicHiddens {
return _dynamicDrawings;
}

- (NSRunLoopMode)mainRunLoopMode {
if (!_mainRunLoopMode) {
_mainRunLoopMode = NSRunLoopCommonModes;
}
return _mainRunLoopMode;
}

@end
11 changes: 10 additions & 1 deletion Source/SVGAVideoEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ @implementation SVGAVideoEntity

static NSCache *videoCache;
static NSMapTable * weakCache;
static dispatch_semaphore_t videoSemaphore;

+ (void)load {
static dispatch_once_t onceToken;
Expand All @@ -40,6 +41,7 @@ + (void)load {
weakCache = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory
valueOptions:NSPointerFunctionsWeakMemory
capacity:64];
videoSemaphore = dispatch_semaphore_create(1);
});
}

Expand Down Expand Up @@ -209,19 +211,26 @@ - (void)resetAudiosWithProtoObject:(SVGAProtoMovieEntity *)protoObject {
}

+ (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
Expand Down

0 comments on commit 5b3e530

Please sign in to comment.