
- Removed YuMi/Library/ (138 MB, not tracked) - Removed YuMi/Resources/ (23 MB, not tracked) - Removed old version assets (566 files, not tracked) - Excluded Pods/, xcuserdata/ and other build artifacts - Clean repository optimized for company server deployment
112 lines
3.1 KiB
Objective-C
112 lines
3.1 KiB
Objective-C
//
|
|
// SVGAParserManager.m
|
|
// YMhat
|
|
//
|
|
// Created by 卫明何 on 2018/4/11.
|
|
// Copyright © 2018年 XC. All rights reserved.
|
|
//
|
|
|
|
#import "SVGAParserManager.h"
|
|
#import "YYUtility.h"
|
|
#import "GCDHelper.h"
|
|
#import "YUMIMacroUitls.h"
|
|
|
|
static NSInteger retryCount = 3;
|
|
|
|
@interface SVGAParserManager ()
|
|
@property (nonatomic,strong) NSMutableDictionary *parserQueue;
|
|
@property (nonatomic,strong) NSMutableDictionary *retryCache;
|
|
@property (nonatomic,strong) SVGAParser *parser;
|
|
|
|
@end
|
|
|
|
@implementation SVGAParserManager
|
|
- (void)loadSvgaWithURL:(NSURL *)url
|
|
completionBlock:(void (^)(SVGAVideoEntity * _Nullable))completionBlock
|
|
failureBlock:(void (^)(NSError * _Nullable))failureBlock {
|
|
if (!url) return;
|
|
@kWeakify(self);
|
|
NSString *key = [self cacheURL:url];
|
|
[self.parser parseWithURL:url completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
@kStrongify(self);
|
|
dispatch_main_sync_safe(^{
|
|
@kStrongify(self);
|
|
if (videoItem) {
|
|
completionBlock(videoItem);
|
|
[self removeCacheWithKey:key];
|
|
[self.retryCache removeObjectForKey:key];
|
|
}
|
|
});
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
@kStrongify(self);
|
|
if (error) {
|
|
if (![self.retryCache objectForKey:key]) {
|
|
[self.retryCache setObject:@(0) forKey:key];
|
|
}
|
|
[self.retryCache setObject:@([[self.retryCache objectForKey:key] integerValue] + 1) forKey:key];
|
|
if ([[self.retryCache objectForKey:key] integerValue] < retryCount) {
|
|
[self retryWithKey:key completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
completionBlock(videoItem);
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
failureBlock(error);
|
|
}];
|
|
}
|
|
}
|
|
}];
|
|
}
|
|
|
|
// 尝试重新播放
|
|
- (void)retryWithKey:(NSString *)key
|
|
completionBlock:(void (^)(SVGAVideoEntity * _Nullable))completionBlock
|
|
failureBlock:(void (^)(NSError * _Nullable))failureBlock {
|
|
if (key) {
|
|
NSURL *url = [self.parserQueue objectForKey:key];
|
|
[self loadSvgaWithURL:url completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
completionBlock(videoItem);
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
|
|
}];
|
|
}
|
|
}
|
|
|
|
// 缓存url
|
|
- (NSString *)cacheURL:(NSURL *)url {
|
|
NSString *key = [self getUUid];
|
|
[self.parserQueue setObject:url forKey:key];
|
|
return key;
|
|
}
|
|
|
|
|
|
- (void)removeCacheWithKey:(NSString *)key {
|
|
[self.parserQueue removeObjectForKey:key];
|
|
}
|
|
|
|
- (NSString *)getUUid {
|
|
return [UIDevice currentDevice].identifierForVendor.UUIDString;
|
|
}
|
|
|
|
#pragma mark - Getter
|
|
|
|
- (SVGAParser *)parser {
|
|
if (_parser == nil) {
|
|
_parser = [[SVGAParser alloc]init];
|
|
}
|
|
return _parser;
|
|
}
|
|
|
|
- (NSMutableDictionary *)parserQueue {
|
|
if (_parserQueue == nil) {
|
|
_parserQueue = [NSMutableDictionary dictionary];
|
|
}
|
|
return _parserQueue;
|
|
}
|
|
|
|
- (NSMutableDictionary *)retryCache {
|
|
if (_retryCache == nil) {
|
|
_retryCache = [NSMutableDictionary dictionary];
|
|
}
|
|
return _retryCache;
|
|
}
|
|
|
|
@end
|