260 lines
10 KiB
Objective-C
260 lines
10 KiB
Objective-C
//
|
|
// QXUserCpDressView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/11/19.
|
|
//
|
|
|
|
#import "QXUserCpDressView.h"
|
|
#import "QXEffectSvgaView.h"
|
|
#import "QGVAPWrapView.h"
|
|
#import "UIView+VAP.h"
|
|
#import "QXFileManager.h"
|
|
|
|
@interface QXUserCpDressView()<VAPWrapViewDelegate>
|
|
@property (nonatomic,strong)QXEffectSvgaView *svgaView;
|
|
@property (nonatomic,strong)QGVAPWrapView *mp4View;
|
|
|
|
|
|
@property (nonatomic,strong)UIImageView *headerView1;
|
|
@property (nonatomic,strong)UIImageView *headerView2;
|
|
|
|
@property (nonatomic,strong) NSString *videoPath;
|
|
@end
|
|
@implementation QXUserCpDressView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)initSubviews{
|
|
|
|
self.headerView1 = [[UIImageView alloc] init];
|
|
self.headerView1.contentMode = UIViewContentModeScaleAspectFill;
|
|
[self.headerView1 addRoundedCornersWithRadius:ScaleWidth(30)/2];
|
|
[self addSubview:self.headerView1];
|
|
|
|
self.headerView2 = [[UIImageView alloc] init];
|
|
self.headerView2.contentMode = UIViewContentModeScaleAspectFill;
|
|
[self.headerView2 addRoundedCornersWithRadius:ScaleWidth(30)/2];
|
|
[self addSubview:self.headerView2];
|
|
|
|
self.svgaView = [[QXEffectSvgaView alloc] initWithFrame:CGRectMake(ScaleWidth(15),ScaleWidth(15), self.width-ScaleWidth(30), self.height-ScaleWidth(30)) isAutoPlay:YES];
|
|
self.svgaView.hidden = YES;
|
|
[self addSubview:self.svgaView];
|
|
|
|
self.mp4View = [[QGVAPWrapView alloc] initWithFrame:CGRectMake(ScaleWidth(15),ScaleWidth(15), self.width-ScaleWidth(30), self.height-ScaleWidth(30))];
|
|
self.mp4View.hidden = YES;
|
|
// self.mp4View.ap
|
|
self.mp4View.hwd_enterBackgroundOP = HWDMP4EBOperationTypeDoNothing;
|
|
self.mp4View.contentMode = QGVAPWrapViewContentModeScaleToFill;
|
|
self.mp4View.userInteractionEnabled = NO;
|
|
self.mp4View.backgroundColor = [UIColor clearColor];
|
|
self.mp4View.hidden = YES;
|
|
[self addSubview:self.mp4View];
|
|
[self bringSubviewToFront:self.headerView1];
|
|
[self bringSubviewToFront:self.headerView2];
|
|
}
|
|
|
|
-(void)setModel:(QXUserCpInfoModel *)model{
|
|
if (_model!=nil) {
|
|
return;
|
|
}
|
|
_model = model;
|
|
if ([model.user_info1.user_id isEqualToString:QXGlobal.shareGlobal.loginModel.user_id]) {
|
|
[self.headerView1 sd_setImageWithURL:[NSURL URLWithString:model.user_info1.avatar]];
|
|
[self.headerView2 sd_setImageWithURL:[NSURL URLWithString:model.user_info2.avatar]];
|
|
}else{
|
|
[self.headerView1 sd_setImageWithURL:[NSURL URLWithString:model.user_info2.avatar]];
|
|
[self.headerView2 sd_setImageWithURL:[NSURL URLWithString:model.user_info1.avatar]];
|
|
}
|
|
[self displayDressWithDressUrl:model.pendant];
|
|
if (model.direction.intValue == 0) {
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self).offset(ScaleWidth(30));
|
|
make.centerX.equalTo(self).offset(-(ScaleWidth(15)+4));
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.headerView1);
|
|
make.left.equalTo(self.headerView1.mas_right).offset(8);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
return;
|
|
}else if (model.direction.intValue == 1) {
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(self).offset(0);
|
|
make.top.equalTo(self).offset(ScaleWidth(30));
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.headerView1.mas_bottom).offset(8);
|
|
make.right.equalTo(self.headerView1);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
return;
|
|
}else if (model.direction.intValue == 2) {
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(self).offset(0);
|
|
make.centerY.equalTo(self).offset(-(ScaleWidth(15)+4));
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.headerView1.mas_bottom).offset(8);
|
|
make.right.equalTo(self.headerView1);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
return;
|
|
}else if (model.direction.intValue == 3) {
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.equalTo(self).offset(-ScaleWidth(30));
|
|
make.right.equalTo(self).offset(0);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(self.headerView2);
|
|
make.bottom.equalTo(self.headerView2.mas_top).offset(-8);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
|
|
return;
|
|
}else if (model.direction.intValue == 4) {
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.equalTo(self).offset(-ScaleWidth(30));
|
|
make.centerX.equalTo(self).offset(-(ScaleWidth(15)+4));
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.headerView1);
|
|
make.left.equalTo(self.headerView1.mas_right).offset(8);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
return;
|
|
}else if (model.direction.intValue == 5) {
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.equalTo(self).offset(-ScaleWidth(30));
|
|
make.left.equalTo(self).offset(0);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self.headerView2);
|
|
make.bottom.equalTo(self.headerView2.mas_top).offset(-8);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
return;
|
|
}else if (model.direction.intValue == 6) {
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self).offset(0);
|
|
make.centerY.equalTo(self).offset(-(ScaleWidth(15)+4));
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.headerView1.mas_bottom).offset(8);
|
|
make.right.equalTo(self.headerView1);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
return;
|
|
}else if (model.direction.intValue == 7) {
|
|
[self.headerView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self).offset(0);
|
|
make.top.equalTo(self).offset(ScaleWidth(30));
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
[self.headerView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.headerView1.mas_bottom).offset(8);
|
|
make.left.equalTo(self.headerView1);
|
|
make.width.height.mas_equalTo(ScaleWidth(30));
|
|
}];
|
|
return;
|
|
}
|
|
}
|
|
-(void)hideHeader{
|
|
self.headerView1.hidden = YES;
|
|
self.headerView2.hidden = YES;
|
|
}
|
|
-(void)headerStartPlay{
|
|
[self playHWDMP4];
|
|
}
|
|
-(void)displayDressWithDressUrl:(NSString*)dressUrl{
|
|
[self stopHWDMP4];
|
|
if (dressUrl.length > 0 && ([dressUrl hasPrefix:@"http"] || [dressUrl hasPrefix:@"https"])) {
|
|
if ([dressUrl isExist]) {
|
|
if ([dressUrl hasSuffix:@"svga"]) {
|
|
[self.svgaView setHidden:NO];
|
|
[self.mp4View stopHWDMP4];
|
|
[self.mp4View setHidden:YES];
|
|
[self.svgaView destroySvga];
|
|
[self.svgaView loadSVGAPlayerWith:dressUrl inBundle:NO loop:INTMAX_MAX];
|
|
}else if ([dressUrl hasSuffix:@"mp4"]){
|
|
[self.svgaView setHidden:YES];
|
|
[self.mp4View setHidden:NO];
|
|
[self.mp4View stopHWDMP4];
|
|
MJWeakSelf
|
|
[[QXRequset shareInstance] downloadVideoPlayerWithUrl:dressUrl completion:^(BOOL result, NSString * _Nonnull fileName) {
|
|
NSString *videoPath = [QXFileManager getGiftVideoPath:dressUrl.lastPathComponent];
|
|
weakSelf.videoPath = videoPath;
|
|
[weakSelf.mp4View setMute:YES];
|
|
// videoPath = [[NSBundle mainBundle] pathForResource:@"4150" ofType:@"mp4"];
|
|
[weakSelf.mp4View playHWDMP4:videoPath repeatCount:INTMAX_MAX delegate:self];
|
|
}];
|
|
}else{
|
|
[self.mp4View stopHWDMP4];
|
|
[self.svgaView destroySvga];
|
|
[self.svgaView setHidden:YES];
|
|
[self.mp4View setHidden:YES];
|
|
}
|
|
} else {
|
|
[self.mp4View stopHWDMP4];
|
|
[self.svgaView destroySvga];
|
|
[self.svgaView setHidden:YES];
|
|
[self.mp4View setHidden:YES];
|
|
}
|
|
}
|
|
}
|
|
-(void)stopHWDMP4{
|
|
if (![self.model.pendant isExist]) {
|
|
return;
|
|
}
|
|
[self.mp4View stopHWDMP4];
|
|
}
|
|
-(void)playHWDMP4{
|
|
if (![self.model.pendant isExist]) {
|
|
return;
|
|
}
|
|
[self.mp4View setMute:YES];
|
|
[self.mp4View playHWDMP4:self.videoPath repeatCount:INTMAX_MAX delegate:self];
|
|
}
|
|
-(void)resetView{
|
|
[self.headerView1 sd_cancelLatestImageLoad];
|
|
[self.headerView2 sd_cancelLatestImageLoad];
|
|
self.headerView1.image = nil;
|
|
self.headerView2.image = nil;
|
|
[self stopHWDMP4];
|
|
_model = nil;
|
|
}
|
|
//- (QXEffectSvgaView *)svgaView {
|
|
// if (!_svgaView) {
|
|
// _svgaView = [[QXEffectSvgaView alloc] initWithFrame:CGRectZero isAutoPlay:YES];
|
|
// _svgaView.hidden = YES;
|
|
// }
|
|
// return _svgaView;
|
|
//}
|
|
//- (QGVAPWrapView *)mp4View {
|
|
// if (!_mp4View) {
|
|
// _mp4View = [[QGVAPWrapView alloc] initWithFrame:CGRectZero];
|
|
// _mp4View.hwd_enterBackgroundOP = HWDMP4EBOperationTypeDoNothing;
|
|
// _mp4View.contentMode = UIViewContentModeScaleAspectFill;
|
|
// _mp4View.userInteractionEnabled = NO;
|
|
// _mp4View.backgroundColor = [UIColor clearColor];
|
|
// _mp4View.hidden = YES;
|
|
// }
|
|
// return _mp4View;
|
|
//}
|
|
@end
|