// // QXSeatHeaderView.m // QXLive // // Created by 启星 on 2025/5/6. // #import "QXSeatHeaderView.h" #import "QXEffectSvgaView.h" #import "UIView+VAP.h" #import "QXFileManager.h" @interface QXSeatHeaderView() @property (nonatomic,strong) QXEffectSvgaView *svgaView; @property (nonatomic,strong) VAPView *mp4View; @property (nonatomic,strong) NSString *dress; @property (nonatomic,strong) NSString *videoPath; @end @implementation QXSeatHeaderView - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { [self initSubViews]; } return self; } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; } return self; } -(void)layoutSubviews{ [super layoutSubviews]; [self.headImageView addRoundedCornersWithRadius:self.headImageView.height/2]; // [self.svgaView addRoundedCornersWithRadius:self.headImageView.height/2-2]; } -(void)initSubViews{ self.headImageView = [[UIImageView alloc] init]; self.headImageView.image = [UIImage imageNamed:@"user_header_placehoulder"]; self.headImageView.contentMode = UIViewContentModeScaleAspectFill; self.headImageView.clipsToBounds = YES; [self addSubview:self.headImageView]; [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.top.equalTo(self); }]; [self addSubview:self.svgaView]; [self.svgaView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.equalTo(self).offset(-6); make.right.bottom.equalTo(self).offset(6); }]; [self addSubview:self.mp4View]; [self.mp4View mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.equalTo(self).offset(-6); make.right.bottom.equalTo(self).offset(6); }]; } -(void)setHeadIcon:(NSString *)headerIcon dress:(nonnull NSString *)dress{ _dress = dress; NSString *dressUrl = [dress stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; [self.headImageView sd_setImageWithURL:[NSURL URLWithString:headerIcon] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]]; 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 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]; } }else{ [self.mp4View stopHWDMP4]; [self.svgaView destroySvga]; [self.svgaView setHidden:YES]; [self.mp4View setHidden:YES]; } } -(void)stopHWDMP4{ if (![_dress isExist]) { return; } [self.mp4View stopHWDMP4]; } -(void)playHWDMP4{ if (![_dress isExist]) { return; } [self.mp4View playHWDMP4:self.videoPath repeatCount:INTMAX_MAX delegate:self]; } - (QXEffectSvgaView *)svgaView { if (!_svgaView) { _svgaView = [[QXEffectSvgaView alloc] initWithFrame:CGRectZero isAutoPlay:YES]; _svgaView.hidden = YES; } return _svgaView; } - (VAPView *)mp4View { if (!_mp4View) { _mp4View = [[VAPView alloc] initWithFrame:CGRectZero]; _mp4View.hwd_enterBackgroundOP = HWDMP4EBOperationTypeDoNothing; _mp4View.contentMode = UIViewContentModeScaleAspectFit; _mp4View.userInteractionEnabled = NO; _mp4View.backgroundColor = [UIColor clearColor]; _mp4View.hidden = YES; } return _mp4View; } @end