Files
featherVoice/QXLive/Room(房间)/View/直播/QXSeatHeaderView.m

138 lines
4.7 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXSeatHeaderView.m
// QXLive
//
// Created by on 2025/5/6.
//
#import "QXSeatHeaderView.h"
#import "QXEffectSvgaView.h"
#import "UIView+VAP.h"
#import "QXFileManager.h"
@interface QXSeatHeaderView()<HWDMP4PlayDelegate>
@property (nonatomic,strong) QXEffectSvgaView *svgaView;
@property (nonatomic,strong) VAPView *mp4View;
2025-10-20 09:43:10 +08:00
@property (nonatomic,strong) NSString *dress;
@property (nonatomic,strong) NSString *videoPath;
2025-08-08 10:49:36 +08:00
@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
2025-10-20 09:43:10 +08:00
dress:(nonnull NSString *)dress{
_dress = dress;
NSString *dressUrl = [dress stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
2025-08-08 10:49:36 +08:00
[self.headImageView sd_setImageWithURL:[NSURL URLWithString:headerIcon] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
2025-10-20 09:43:10 +08:00
if (dressUrl.length > 0 && ([dressUrl hasPrefix:@"http"] || [dressUrl hasPrefix:@"https"])) {
if ([dressUrl isExist]) {
if ([dressUrl hasSuffix:@"svga"]) {
2025-08-08 10:49:36 +08:00
[self.svgaView setHidden:NO];
[self.mp4View stopHWDMP4];
[self.mp4View setHidden:YES];
[self.svgaView destroySvga];
2025-10-20 09:43:10 +08:00
[self.svgaView loadSVGAPlayerWith:dressUrl inBundle:NO loop:INTMAX_MAX];
}else if ([dressUrl hasSuffix:@"mp4"]){
2025-08-08 10:49:36 +08:00
[self.svgaView setHidden:YES];
[self.mp4View setHidden:NO];
[self.mp4View stopHWDMP4];
MJWeakSelf
2025-10-20 09:43:10 +08:00
[[QXRequset shareInstance] downloadVideoPlayerWithUrl:dressUrl completion:^(BOOL result, NSString * _Nonnull fileName) {
NSString *videoPath = [QXFileManager getGiftVideoPath:dressUrl.lastPathComponent];
weakSelf.videoPath = videoPath;
2025-08-08 10:49:36 +08:00
[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];
}
}
2025-10-20 09:43:10 +08:00
-(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];
}
2025-08-08 10:49:36 +08:00
- (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];
2025-10-20 09:43:10 +08:00
_mp4View.hwd_enterBackgroundOP = HWDMP4EBOperationTypeDoNothing;
2025-08-08 10:49:36 +08:00
_mp4View.contentMode = UIViewContentModeScaleAspectFit;
_mp4View.userInteractionEnabled = NO;
_mp4View.backgroundColor = [UIColor clearColor];
_mp4View.hidden = YES;
}
return _mp4View;
}
@end