VAP礼物、座驾播放适配

This commit is contained in:
chenguilong
2022-03-30 18:46:22 +08:00
parent 3d30a06353
commit 9a30f258d8
2 changed files with 62 additions and 56 deletions

View File

@@ -12,6 +12,7 @@
#import <NIMSDK/NIMSDK.h>
#import <POP.h>
#import "QGVAPConfigModel.h"
#import "UIView+VAP.h"
///Tool
#import "XPGiftStorage.h"
#import "XPMacro.h"
@@ -39,7 +40,7 @@
#import "XPRoomNobleLevelUpView.h"
#import "QGVAPWrapView.h"
@interface XPRoomAnimationView ()<SVGAPlayerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate, VAPWrapViewDelegate>
@interface XPRoomAnimationView ()<SVGAPlayerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate, HWDMP4PlayDelegate>
///
///
@property (nonatomic,strong) XPRoomAnimationHitView * lowLevelView;
@@ -54,7 +55,7 @@
///
@property (nonatomic,strong) SVGAImageView *giftEffectView;
///VAP
@property (nonatomic, strong) QGVAPWrapView *vapEffetView;
@property (nonatomic, strong) VAPView *vapGiftEffectView;
///
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
///
@@ -90,7 +91,7 @@
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *carEffectQueue;
@property (nonatomic,strong) SVGAImageView *carEffectView;
///VAP
@property (nonatomic, strong) QGVAPWrapView *carVapEffetView;
@property (nonatomic, strong) VAPView *carVapEffectView;
#pragma mark -
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *enterEffectQueue;
@property (nonatomic,strong) SVGAImageView *enterEffectView;
@@ -320,10 +321,10 @@
NSString *viewUrl = [effectDict objectForKey:@"viewUrl"];
NSString *carEffect = [effectDict objectForKey:@"effect"];
if (viewUrl.length) {
self.carVapEffetView.hidden = NO;
if (self.carVapEffetView.superview == nil) {
[self.middleLevelView addSubview:self.carVapEffetView];
[self.carVapEffetView mas_makeConstraints:^(MASConstraintMaker *make) {
self.carVapEffectView.hidden = NO;
if (self.carVapEffectView.superview == nil) {
[self.middleLevelView addSubview:self.carVapEffectView];
[self.carVapEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.middleLevelView);
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenHeight);
@@ -331,8 +332,8 @@
}
[self.vapParser parseWithURL:viewUrl completionBlock:^(NSString * _Nullable videoUrl) {
if (videoUrl.length) {
[self.carVapEffetView setMute:YES];
[self.carVapEffetView playHWDMP4:videoUrl repeatCount:1 delegate:self];
[self.carVapEffectView setMute:YES];
[self.carVapEffectView playHWDMP4:videoUrl repeatCount:1 delegate:self];
}
} failureBlock:^(NSError * _Nullable error) {
@@ -351,13 +352,13 @@
CGFloat width = videoItem.videoSize.width;
CGFloat height = videoItem.videoSize.height;
if (width > height) {
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFit;
self.carEffectView.contentMode = UIViewContentModeScaleAspectFit;
} else {//
CGFloat resizeH = KScreenWidth * height / width;//
if (resizeH > KScreenHeight) {//
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFill;
self.carEffectView.contentMode = UIViewContentModeScaleAspectFill;
} else {//
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFit;
self.carEffectView.contentMode = UIViewContentModeScaleAspectFit;
}
}
self.carEffectView.hidden = NO;
@@ -1014,10 +1015,10 @@
/// vap
- (void)playGiftEffectWithVapUrl:(NSString *)vapUrl {
self.vapEffetView.hidden = NO;
if (self.vapEffetView.superview == nil) {
[self.middleLevelView addSubview:self.vapEffetView];
[self.vapEffetView mas_makeConstraints:^(MASConstraintMaker *make) {
self.vapGiftEffectView.hidden = NO;
if (self.vapGiftEffectView.superview == nil) {
[self.middleLevelView addSubview:self.vapGiftEffectView];
[self.vapGiftEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.middleLevelView);
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenHeight);
@@ -1025,8 +1026,8 @@
}
[self.vapParser parseWithURL:vapUrl completionBlock:^(NSString * _Nullable videoUrl) {
if (videoUrl.length) {
[self.vapEffetView setMute:YES];
[self.vapEffetView playHWDMP4:videoUrl repeatCount:1 delegate:self];
[self.vapGiftEffectView setMute:YES];
[self.vapGiftEffectView playHWDMP4:videoUrl repeatCount:1 delegate:self];
}
} failureBlock:^(NSError * _Nullable error) {
@@ -1067,39 +1068,40 @@
}
}
#pragma mark - VAPWrapViewDelegate
- (BOOL)vapWrap_viewshouldStartPlayMP4:(VAPView *)container config:(QGVAPConfigModel *)config {
CGFloat width = config.info.videoSize.width;
CGFloat height = config.info.videoSize.height;
if (width > height) {
container.contentMode = UIViewContentModeScaleAspectFit;
} else {//
CGFloat resizeH = KScreenWidth * height / width;//
if (resizeH > KScreenHeight) {//
container.contentMode = UIViewContentModeScaleAspectFill;
} else {//
container.contentMode = UIViewContentModeScaleAspectFit;
}
}
#pragma mark - HWDMP4PlayDelegate
//truefalse
- (BOOL)shouldStartPlayMP4:(VAPView *)container config:(QGVAPConfigModel *)config {
CGFloat width = config.info.size.width;
CGFloat height = config.info.size.height;
container.center = self.center;
[container mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenWidth * height / width);
}];
return YES;
}
- (void)vapWrap_viewDidFinishPlayMP4:(NSInteger)totalFrameCount view:(VAPView *)container {
- (void)viewDidFinishPlayMP4:(NSInteger)totalFrameCount view:(VAPView *)container {
dispatch_async(dispatch_get_main_queue(), ^{
if (container.superview == self.carVapEffetView) {
self.carVapEffetView.hidden = YES;
[self.carVapEffetView removeFromSuperview];
if (container == self.carVapEffectView) {
[self.carVapEffectView removeFromSuperview];
self.carVapEffectView = nil;
[self.carEffectQueue removeObjectAtIndex:0];
if (self.carEffectQueue.count > 0) {
[self playCarEffect:self.carEffectQueue.firstObject];
}
} else if (container.superview == self.vapEffetView) {
self.vapEffetView.hidden = YES;
} else if (container == self.vapGiftEffectView) {
[self.vapGiftEffectView removeFromSuperview];
self.vapGiftEffectView = nil;
}
});
}
- (void)viewDidFailPlayMP4:(NSError *)error {
}
#pragma mark - Getters And Setters
- (SVGAImageView *)giftEffectView {
if (!_giftEffectView) {
@@ -1112,26 +1114,24 @@
return _giftEffectView;
}
- (QGVAPWrapView *)vapEffetView {
if (!_vapEffetView) {
_vapEffetView = [[QGVAPWrapView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_vapEffetView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
_vapEffetView.hidden = YES;
_vapEffetView.contentMode = QGVAPWrapViewContentModeAspectFit;
_vapEffetView.autoDestoryAfterFinish = YES;
- (VAPView *)vapGiftEffectView {
if (!_vapGiftEffectView) {
_vapGiftEffectView = [[VAPView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_vapGiftEffectView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
_vapGiftEffectView.contentMode = UIViewContentModeScaleAspectFill;
_vapGiftEffectView.hidden = YES;
}
return _vapEffetView;
return _vapGiftEffectView;
}
- (QGVAPWrapView *)carVapEffetView {
if (!_carVapEffetView) {
_carVapEffetView = [[QGVAPWrapView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_carVapEffetView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
_carVapEffetView.hidden = YES;
_carVapEffetView.contentMode = QGVAPWrapViewContentModeAspectFit;
_carVapEffetView.autoDestoryAfterFinish = YES;
- (VAPView *)carVapEffectView {
if (!_carVapEffectView) {
_carVapEffectView = [[VAPView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
_carVapEffectView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
_carVapEffectView.contentMode = UIViewContentModeScaleAspectFill;
_carVapEffectView.hidden = YES;
}
return _carVapEffetView;
return _carVapEffectView;
}
- (XPRoomGiftAnimationParser *)vapParser {

View File

@@ -52,7 +52,13 @@ static NSOperationQueue *parseQueue;
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
if (!error) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
completionBlock(filePath.absoluteString);
NSString *str;
if ([filePath.absoluteString hasPrefix:@"file:///"]) {
str = [filePath.absoluteString stringByReplacingOccurrencesOfString:@"file://" withString:@""];
} else {
str = filePath.absoluteString;
}
completionBlock(str);
}];
} else {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{