房间播放背景音乐的时候最小化 从最小化进入房间的时候显示异常的问题

This commit is contained in:
fengshuo
2022-05-11 20:38:09 +08:00
parent d84a0aaa1b
commit 9daea5a3a6
26 changed files with 426 additions and 127 deletions

View File

@@ -26,6 +26,7 @@
#import "XPConstant.h"
#import "Api+RoomSetting.h"
#import "RtcManager.h"
#import "XPRoomMiniManager.h"
///Model
#import "RoomInfoModel.h"
#import "MicroQueueModel.h"
@@ -70,7 +71,7 @@
#import "XPAnchorPkPanelView.h"
#import "XPWebViewController.h"
@interface XPRoomFunctionContainerView ()<XPAcrpssRoomPKPanelViewDelegate, XPRoomLittleGameListViewDelegate, XPAnchorPkPanelViewDelegate>
@interface XPRoomFunctionContainerView ()<XPAcrpssRoomPKPanelViewDelegate, XPRoomLittleGameListViewDelegate, XPAnchorPkPanelViewDelegate, XPRoomBackMusicPlayerViewDelegate>
///host
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
///
@@ -168,6 +169,10 @@
[self.littleGameMiniView hiddenSudGamePostionView];
}
- (Music *)getCurrentMusic {
return self.musicPlayView.currentMusic;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.contributeEnterView];
@@ -183,6 +188,7 @@
make.width.mas_equalTo(116);
make.height.mas_equalTo(22);
}];
[self.topicStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.height.mas_equalTo(15);
@@ -322,6 +328,13 @@
[self updateContrionEntranceWithRoomUid:[NSString stringWithFormat:@"%ld", roomInfo.uid] type:@"day"];
}
}
if (roomInfo.type == RoomType_MiniGame) {
} else {
}
[self updateRoomTopic];
[self showLittleGameMiniView:roomInfo.type micCount:roomInfo.mgMicNum];
[self configLittleGameState];
@@ -390,6 +403,18 @@
[self updateRoomTopic];
[self showLittleGameMiniView:roomInfo.type micCount:roomInfo.mgMicNum];
[self configLittleGameState];
[self configPlayMusicRoomTypeChange];
}
- (void)onRoomMiniEntered {
if ([XPRoomMiniManager shareManager].getCurrentMusic) {
if (!self.musicPlayView.superview) {
[self addSubview:self.musicPlayView];
self.musicPlayView.frame = CGRectMake(-KScreenWidth, kNavigationHeight + 4, KScreenWidth - 85, 80);
}
[self.musicPlayView configCurrentPlayingMusic:[XPRoomMiniManager shareManager].getCurrentMusic];
[[XPRoomMiniManager shareManager] configCurrentMusic:nil];
}
}
- (void)handleNIMCustomMessage:(NIMMessage *)message {
@@ -671,27 +696,39 @@
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
if (self.delegate.getRoomInfo.type == RoomType_MiniGame) {
[self.littleGameMiniView needRefreshPosition:queue];
}
MicroQueueModel * currentUserModel;
NSString * uid = [AccountInfoStorage instance].getUid;
for (MicroQueueModel * microModel in queue.allValues) {
if (microModel.userInfo && microModel.userInfo.uid == uid.integerValue) {
currentUserModel = microModel;
}else {
MicroQueueModel * currentUserModel;
NSString * uid = [AccountInfoStorage instance].getUid;
for (MicroQueueModel * microModel in queue.allValues) {
if (microModel.userInfo && microModel.userInfo.uid == uid.integerValue) {
currentUserModel = microModel;
}
}
}
if (currentUserModel) {
if (!self.musicEnterButton.superview) {
[self addSubview:self.musicEnterButton];
[self.musicEnterButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(0).offset(8);
make.top.mas_equalTo(kNavigationHeight+4);
make.width.mas_equalTo(79);
make.height.mas_equalTo(22);
}];
}
} else {
if (self.musicEnterButton) {
[self.musicEnterButton removeFromSuperview];
if (currentUserModel) {
if (!self.musicEnterButton.superview) {
[self addSubview:self.musicEnterButton];
[self.musicEnterButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(0).offset(8);
make.top.mas_equalTo(kNavigationHeight+4);
make.width.mas_equalTo(79);
make.height.mas_equalTo(22);
}];
}
} else {
[[RtcManager instance] changePlayState:BackMusicPlayState_Stop];
if (self.musicEnterButton) {
[self.musicEnterButton removeFromSuperview];
}
POPBasicAnimation *moveAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewCenter];
moveAnimation.fromValue = [NSValue valueWithCGPoint:self.musicPlayView.center];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(-KScreenWidth, self.musicPlayView.center.y)];
moveAnimation.beginTime = CACurrentMediaTime();
moveAnimation.duration = 0.5;
moveAnimation.repeatCount = 1;
moveAnimation.removedOnCompletion = YES;
[self.musicPlayView pop_addAnimation:moveAnimation forKey:@"moveOutAnimation"];
[self.musicPlayView resetData];
[self.musicPlayView removeFromSuperview];
}
}
}
@@ -787,6 +824,15 @@
self.delegate.getRoomInfo.pkState = AcrossRoomPkStateTypePenaltyEnd;
}
#pragma mark - XPRoomBackMusicPlayerViewDelegate
- (void)xPRoomBackMusicPlayerView:(XPRoomBackMusicPlayerView *)view musicPlaying:(BOOL)musicPlaying {
if (musicPlaying) {
[self resumeLayer:self.musicEnterButton.imageView.layer];
} else {
[self pauseLayer:self.musicEnterButton.imageView.layer];
}
}
#pragma mark - Event Response
- (void)contributionButtonAction:(UITapGestureRecognizer *)tap {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
@@ -1253,6 +1299,52 @@
}
}
#pragma mark -
-(void)pauseLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
- (void)configPlayMusicRoomTypeChange {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
if (roomInfo.type == RoomType_MiniGame) {
[self pauseLayer:self.musicEnterButton.imageView.layer];
[self.musicEnterButton removeFromSuperview];
[self.musicPlayView resetData];
[self.musicPlayView removeFromSuperview];
[[RtcManager instance] changePlayState:BackMusicPlayState_Stop];
} else {
MicroQueueModel * currentUserModel;
NSString * uid = [AccountInfoStorage instance].getUid;
for (MicroQueueModel * microModel in self.delegate.getMicroQueue.allValues) {
if (microModel.userInfo && microModel.userInfo.uid == uid.integerValue) {
currentUserModel = microModel;
}
}
if (currentUserModel) {
if (!self.musicEnterButton.superview) {
[self addSubview:self.musicEnterButton];
[self.musicEnterButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(0).offset(8);
make.top.mas_equalTo(kNavigationHeight+4);
make.width.mas_equalTo(79);
make.height.mas_equalTo(22);
}];
}
}
}
}
#pragma mark - Getters And Setters
- (XPRoomRankEntranceView *)contributeEnterView {
if (!_contributeEnterView) {
@@ -1384,6 +1476,14 @@
_musicEnterButton.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);
_musicEnterButton.backgroundColor = UIColorRGBAlpha(0xffffff, 0.2);
[_musicEnterButton addTarget:self action:@selector(musicEnterButtonAction:) forControlEvents:UIControlEventTouchUpInside];
CAKeyframeAnimation *lAni = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
lAni.duration = 1.5;
lAni.repeatCount = HUGE;
lAni.values=@[@0,@(M_PI*2)];
//使
lAni.removedOnCompletion = NO;
lAni.fillMode = kCAFillModeForwards;
[_musicEnterButton.imageView.layer addAnimation:lAni forKey:nil];
}
return _musicEnterButton;
}
@@ -1391,6 +1491,7 @@
- (XPRoomBackMusicPlayerView *)musicPlayView {
if (!_musicPlayView) {
_musicPlayView = [[XPRoomBackMusicPlayerView alloc] init];
_musicPlayView.delegate = self;
}
return _musicPlayView;
}