diff --git a/YuMi/Modules/YMMine/View/Medals/MedalsViewController.m b/YuMi/Modules/YMMine/View/Medals/MedalsViewController.m index 78d5d4bb..e971cdb7 100644 --- a/YuMi/Modules/YMMine/View/Medals/MedalsViewController.m +++ b/YuMi/Modules/YMMine/View/Medals/MedalsViewController.m @@ -61,6 +61,7 @@ typedef enum : NSInteger { @property (nonatomic, strong) XPRoomGiftAnimationParser *mp4Parser; @property (nonatomic, strong) UILabel *otherNameLabel; @property (nonatomic, strong) UILabel *otherCountLabel; +@property (nonatomic, strong) UserMedalsModel *otherMedalsModel; // 自动轮播相关属性 @property (nonatomic, strong) NSTimer *autoScrollTimer; @@ -106,6 +107,7 @@ typedef enum : NSInteger { - (void)dealloc { [self stopAutoScroll]; + [self stopOtherMedalMP4Playback]; } - (void)viewDidLoad { @@ -142,6 +144,9 @@ typedef enum : NSInteger { // 停止自动轮播 [self stopAutoScroll]; + + // 停止其他用户勋章的MP4播放 + [self stopOtherMedalMP4Playback]; } - (void)stopAllCellsPlayback { @@ -344,6 +349,13 @@ typedef enum : NSInteger { make.trailing.mas_equalTo(bg).offset(-15); make.size.mas_equalTo(CGSizeMake(80, 80)); }]; + + [self.view addSubview:self.otherMP4View]; + [self.otherMP4View mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerY.mas_equalTo(bg); + make.trailing.mas_equalTo(bg).offset(-15); + make.size.mas_equalTo(CGSizeMake(80, 80)); + }]; } - (void)setupCenterTabs { @@ -691,10 +703,99 @@ typedef enum : NSInteger { } - (void)_updateOtherInfo:(UserMedalsModel *)userModel { + _otherMedalsModel = userModel; if (self.displayType == MedalsCenterDisplayType_Other) { self.otherAvatar.imageUrl = userModel.avatar; self.otherNameLabel.text = userModel.nick; self.otherCountLabel.text = @(userModel.medalNum).stringValue; + + MedalVo *useMedal = [[userModel useMedals] xpSafeObjectAtIndex:0]; +#if DEBUG + useMedal = [[MedalVo alloc] init]; + useMedal.picUrl = @"https://image.pekolive.com/V1.mp4"; +#endif + if (useMedal) { + if ([useMedal.picUrl hasSuffix:@"mp4"]) { + // 显示客态的 MP4 播放 + [self displayOtherMedalMp4:useMedal.picUrl]; + } else { + // 显示客态的 图片 + [self displayOtherMedalImage:useMedal.picUrl]; + } + } else { + // 没有勋章时显示默认图片 + [self displayOtherMedalImage:nil]; + } + } +} + +#pragma mark - 其他用户勋章显示方法 + +/** + * 显示其他用户的勋章图片 + * @param imageUrl 图片URL,如果为nil则显示默认图片 + */ +- (void)displayOtherMedalImage:(NSString *)imageUrl { + // 停止MP4播放 + [self stopOtherMedalMP4Playback]; + + // 显示图片,隐藏MP4视图 + self.otherMP4View.hidden = YES; + self.otherMedal.hidden = NO; + + if (imageUrl && imageUrl.length > 0) { + self.otherMedal.imageUrl = imageUrl; + } else { + // 显示默认空勋章图片 + self.otherMedal.image = kImage(@"medals_empty"); + } +} + +/** + * 显示其他用户的勋章MP4动画 + * @param mp4Url MP4文件URL + */ +- (void)displayOtherMedalMp4:(NSString *)mp4Url { + if (!mp4Url || mp4Url.length == 0) { + [self displayOtherMedalImage:nil]; + return; + } + + // 停止之前的MP4播放 + [self stopOtherMedalMP4Playback]; + + // 显示MP4视图,隐藏图片 + self.otherMP4View.hidden = NO; + self.otherMedal.hidden = YES; + + // 初始化MP4解析器 + if (!self.mp4Parser) { + self.mp4Parser = [[XPRoomGiftAnimationParser alloc] init]; + } + + @kWeakify(self); + [self.mp4Parser parseWithURL:mp4Url + completionBlock:^(NSString * _Nullable videoUrl) { + @kStrongify(self); + if (![NSString isEmpty:videoUrl] && !self.otherMP4View.hidden) { + // 静音播放,因为是展示其他用户的勋章 + [self.otherMP4View setMute:YES]; + [self.otherMP4View playHWDMP4:videoUrl repeatCount:-1 delegate:nil]; + } + } failureBlock:^(NSError * _Nullable error) { + @kStrongify(self); + NSLog(@"Failed to parse other user medal mp4: %@", error); + // 播放失败时显示图片 + [self displayOtherMedalImage:nil]; + }]; +} + +/** + * 停止其他用户勋章的MP4播放 + */ +- (void)stopOtherMedalMP4Playback { + if (self.otherMP4View) { + [self.otherMP4View stopHWDMP4]; } } @@ -1049,7 +1150,7 @@ typedef enum : NSInteger { _medalsCyclePagerView = [[TYCyclePagerView alloc] init]; _medalsCyclePagerView.dataSource = self; _medalsCyclePagerView.delegate = self; - _medalsCyclePagerView.backgroundColor = [UIColor redColor];//[UIColor clearColor]; + _medalsCyclePagerView.backgroundColor = [UIColor clearColor]; _medalsCyclePagerView.isInfiniteLoop = NO; _medalsCyclePagerView.clipsToBounds = NO; // _medalsCyclePagerView.autoScrollInterval = 0; // 禁用自动滚动 @@ -1062,4 +1163,12 @@ typedef enum : NSInteger { return _medalsCyclePagerView; } +- (VAPView *)otherMP4View { + if (!_otherMP4View) { + _otherMP4View = [[VAPView alloc] init]; + _otherMP4View.contentMode = UIViewContentModeScaleAspectFit; + } + return _otherMP4View; +} + @end diff --git a/YuMi/Modules/YMMine/View/Medals/MedalsWearingControlCollectionViewCell.m b/YuMi/Modules/YMMine/View/Medals/MedalsWearingControlCollectionViewCell.m index b4e089d0..a328a0dc 100644 --- a/YuMi/Modules/YMMine/View/Medals/MedalsWearingControlCollectionViewCell.m +++ b/YuMi/Modules/YMMine/View/Medals/MedalsWearingControlCollectionViewCell.m @@ -86,18 +86,11 @@ - (void)updateMedal:(MedalVo *)medalVo { if (!medalVo) { self.medalImageView.imageUrl = @""; -#if DEBUG - self.medalImageView.backgroundColor = [UIColor clearColor]; -#endif return; } if (![medalVo.picUrl hasSuffix:@"mp4"]) { self.medalImageView.imageUrl = medalVo.picUrl; } - -#if DEBUG - self.medalImageView.backgroundColor = [UIColor redColor]; -#endif } - (instancetype)initWithFrame:(CGRect)frame