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

Commit

Permalink
feat: Correct mp3 file match in proto image.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanduojian committed Sep 29, 2019
1 parent 2127ab9 commit eb45964
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Source/SVGAVideoEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import "SVGAAudioEntity.h"
#import "Svga.pbobjc.h"

#define MP3_MAGIC_NUMBER "ID3"

@interface SVGAVideoEntity ()

@property (nonatomic, assign) CGSize videoSize;
Expand Down Expand Up @@ -85,7 +87,7 @@ - (void)resetImagesWithJSONObject:(NSDictionary *)JSONObject {
if (imageData != nil) {
UIImage *image = [[UIImage alloc] initWithData:imageData scale:2.0];
if (image != nil) {
[images setObject:image forKey:key];
[images setObject:image forKey:[key stringByDeletingPathExtension]];
}
}
}
Expand Down Expand Up @@ -131,6 +133,14 @@ - (void)resetMovieWithProtoObject:(SVGAProtoMovieEntity *)protoObject {
}
}

+ (BOOL)isMP3Data:(NSData *)data {
BOOL result = NO;
if (!strncmp([data bytes], MP3_MAGIC_NUMBER, strlen(MP3_MAGIC_NUMBER))) {
result = YES;
}
return result;
}

- (void)resetImagesWithProtoObject:(SVGAProtoMovieEntity *)protoObject {
NSMutableDictionary<NSString *, UIImage *> *images = [[NSMutableDictionary alloc] init];
NSMutableDictionary<NSString *, NSData *> *audiosData = [[NSMutableDictionary alloc] init];
Expand All @@ -153,9 +163,7 @@ - (void)resetImagesWithProtoObject:(SVGAProtoMovieEntity *)protoObject {
}
}
else if ([protoImages[key] isKindOfClass:[NSData class]]) {
NSData *fileTag = [protoImages[key] subdataWithRange:NSMakeRange(0, 4)];
NSString *fileTagDes = [fileTag description];
if (![fileTagDes containsString:@"89504e47"]) {
if ([SVGAVideoEntity isMP3Data:protoImages[key]]) {
// mp3
[audiosData setObject:protoImages[key] forKey:key];
} else {
Expand Down Expand Up @@ -208,6 +216,7 @@ @interface SVGAVideoSpriteEntity()

@property (nonatomic, copy) NSString *imageKey;
@property (nonatomic, copy) NSArray<SVGAVideoSpriteFrameEntity *> *frames;
@property (nonatomic, copy) NSString *matteKey;

@end

0 comments on commit eb45964

Please sign in to comment.