feat:新商城增加 svga 播放处理

This commit is contained in:
eggmanQQQ
2024-11-15 18:17:15 +08:00
parent dd247c0688
commit ab4a9cf88b
3 changed files with 87 additions and 4 deletions

View File

@@ -11,6 +11,7 @@
NS_ASSUME_NONNULL_BEGIN
typedef void (^DidTapPlay)(NSString *resourcePath);
typedef void (^FetchDataCompletion)(NSArray <DressUpShopModel *>* modelList);
typedef void (^FetchDataForPage)(NSInteger pageIndex, FetchDataCompletion completion);
@@ -20,7 +21,7 @@ typedef void (^FetchDataForPage)(NSInteger pageIndex, FetchDataCompletion comple
// 名称:类型
@property (nonatomic, copy) NSArray<NSDictionary<NSString *, NSNumber *> *> *items;
@property (nonatomic, copy) FetchDataForPage fetchDataForPage;
@property (nonatomic, copy) DidTapPlay didTapItemPlay;
@end

View File

@@ -20,6 +20,8 @@
@property (nonatomic, strong) UILabel *description_2_label;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, copy) DidTapPlay didTapPlay;
@end
@implementation ShoppingMallItemCard
@@ -77,7 +79,7 @@
make.leading.mas_equalTo(self.bgImageView).offset(1);
make.bottom.trailing.mas_equalTo(self.bgImageView).offset(-1);
make.height.mas_equalTo(45);
}];
}];
[self.contentView addSubview:self.statusLabel];
[self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -97,10 +99,14 @@
self.description_1_label.text = YMLocalizedString(@"1.0.30_text_1");
self.description_2_label.text = YMLocalizedString(@"1.0.30_text_2");
self.statusLabel.text = @"FFUFUFUFUFUFUFUFUUFUFUCKCKCKCKKCKCKCKCKCKCK";//YMLocalizedString(@"1.0.30_text_4");
self.playButton.hidden = !([cellModel.effect.lowercaseString hasSuffix:@"svga"] || [cellModel.effect.lowercaseString hasSuffix:@"mp4"]);
}
- (void)handleTapPlay:(id)sender {
if (_didTapPlay) {
self.didTapPlay(self.cellModel.effect);
}
}
#pragma mark -
@@ -475,7 +481,13 @@
forIndexPath:indexPath];
NSArray *data = self.dataCache[@(collectionView.tag)];
cell.cellModel = [data xpSafeObjectAtIndex:indexPath.row];
if (self.didTapItemPlay) {
@kWeakify(self);
cell.didTapPlay = ^(NSString * _Nonnull resourcePath) {
@kStrongify(self);
self.didTapItemPlay(resourcePath);
};
}
return cell;
}

View File

@@ -7,11 +7,18 @@
#import "ShoppingMallViewController.h"
#import <SVGA.h>
#import <QGVAPWrapView.h>
#import "ShoppingMallDataPresent.h"
#import "ShoppingMallCategoryListView.h"
@interface ShoppingMallViewController ()
@property (nonatomic, strong) UIView *playEffectMask;
@property (nonatomic, strong) VAPView *mp4Effect;
@property (nonatomic, strong) SVGAImageView *svgaEffect;
@end
@implementation ShoppingMallViewController
@@ -44,6 +51,10 @@
@kStrongify(self);
[self fetchDataForPage:pageIndex completion:completion];
};
listView.didTapItemPlay = ^(NSString * _Nonnull resourcePath) {
@kStrongify(self);
[self playItemEffect:resourcePath];
};
[self.view addSubview:listView];
listView.items = @[@{YMLocalizedString(@"XPMineDressUpViewController2") : @1}, //
@@ -65,4 +76,63 @@
}];
}
- (void)playItemEffect:(NSString *)path {
if ([path.lowercaseString hasSuffix:@"svga"]) {
@kWeakify(self);
SVGAParser *p = [[SVGAParser alloc] init];
[p parseWithURL:[NSURL URLWithString:path]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
self.svgaEffect.hidden = NO;
self.svgaEffect.videoItem = videoItem;
[self.svgaEffect startAnimation];
} failureBlock:^(NSError * _Nullable error) {
}];
} else if ([path.lowercaseString hasSuffix:@"mp4"]) {
}
}
- (void)stopItemSVGAEffect {
[self.svgaEffect stopAnimation];
self.svgaEffect.hidden = YES;
self.playEffectMask.hidden = YES;
}
#pragma mark -
- (UIView *)playEffectMask {
if (!_playEffectMask) {
_playEffectMask = [[UIView alloc] initWithFrame:self.view.bounds];
_playEffectMask.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5f];
}
return _playEffectMask;
}
- (SVGAImageView *)svgaEffect {
if (!_svgaEffect) {
_svgaEffect = [[SVGAImageView alloc] init];
_svgaEffect.contentMode = UIViewContentModeScaleAspectFit;
_svgaEffect.autoPlay = YES;
_svgaEffect.loops = 0;
_svgaEffect.clearsAfterStop = YES;
_svgaEffect.hidden = YES;
if (!_playEffectMask) {
[self.view addSubview:self.playEffectMask];
}
[self.view addSubview:_svgaEffect];
[_svgaEffect mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(KScreenHeight - 100);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopItemSVGAEffect)];
[_svgaEffect addGestureRecognizer:tap];
}
return _svgaEffect;
}
@end