chore: Initial clean commit
- Removed YuMi/Library/ (138 MB, not tracked) - Removed YuMi/Resources/ (23 MB, not tracked) - Removed old version assets (566 files, not tracked) - Excluded Pods/, xcuserdata/ and other build artifacts - Clean repository optimized for company server deployment
This commit is contained in:
82
YuMi/Tools/CardManager/XPSkillCardPlayerManager.h
Normal file
82
YuMi/Tools/CardManager/XPSkillCardPlayerManager.h
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// XPSkillCardPlayerManager.h
|
||||
// YuMi
|
||||
//
|
||||
// Created by GreenLand on 2022/3/9.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "UserInfoModel.h"
|
||||
@class BravoGiftTabInfomationModel;
|
||||
|
||||
typedef enum : NSUInteger {
|
||||
MICState_None = 0,
|
||||
MICState_Open = 1,
|
||||
MICState_Close = 2,
|
||||
MICState_Music = 3,
|
||||
} MICState;
|
||||
|
||||
@interface XPSkillCardPlayerManager : NSObject
|
||||
////获取已解锁照片id列表
|
||||
@property(nonatomic,strong) NSMutableArray *photoIdList;
|
||||
///播放器
|
||||
@property (nonatomic, strong) AVAudioPlayer *player;
|
||||
///是否正在播放
|
||||
@property (nonatomic,assign) BOOL isPlay;
|
||||
///播放音量大小
|
||||
@property (nonatomic, assign) CGFloat volume;
|
||||
@property (nonatomic,assign) BOOL isInRoomFirstRecharge;
|
||||
///是否在房间
|
||||
@property (nonatomic,assign) BOOL isInRoom;
|
||||
///是否在房间控制器里,用于播放动画的判断
|
||||
@property (nonatomic,assign) BOOL isInRoomVC;
|
||||
///是否在首充不弹出界面
|
||||
///所在房间的id
|
||||
@property (nonatomic,copy) NSString *roomUid;
|
||||
///我是否在上麦,在麦上时不能录音
|
||||
@property (nonatomic,assign) BOOL isMineInMic;
|
||||
|
||||
// 用户在 mic 的状态
|
||||
@property (nonatomic, assign) MICState micState;
|
||||
|
||||
// 作为全局获取当前用户数据的 model,需要在相关 user/get 调用处更新,目前只在 mine tab 更新
|
||||
@property(nonatomic, strong) UserInfoModel *userInfoModel;
|
||||
|
||||
@property(nonatomic, assign) BOOL is9Mic; // 当前房间是否 9 mic
|
||||
|
||||
+ (instancetype)shareInstance;
|
||||
|
||||
- (void)requestBravoGiftTabInfomation;
|
||||
- (NSArray <BravoGiftTabInfomationModel*>*)loadBravoGiftTabInfomation;
|
||||
|
||||
/**
|
||||
播放一次音频
|
||||
|
||||
@param filePath 本地路径
|
||||
@param completionBlock 播放完成回调
|
||||
*/
|
||||
- (void)playerVoiceWithPath:(NSString *)filePath completionBlock:(void (^)(void))completionBlock;
|
||||
|
||||
/**
|
||||
新的播放一次音频
|
||||
|
||||
@param filePath 本地路径
|
||||
@param completionBlock 播放完成回调
|
||||
*/
|
||||
- (void)playerNewVoiceWithPath:(NSString *)filePath completionBlock:(void (^)(void))completionBlock;
|
||||
/**
|
||||
停止音乐
|
||||
*/
|
||||
- (void)stopMusic;
|
||||
|
||||
/**
|
||||
停止音乐 是否需要执行完成回调(更新UI)
|
||||
*/
|
||||
- (void)stopMusicIsNeedCompletion:(BOOL)isNeedCompletion;
|
||||
///关闭麦克风、听筒
|
||||
- (void)closeMicroAndVoiceWithBroadcast:(BOOL)isBroadcast;
|
||||
///恢复之前的 麦克风、听筒听筒状态
|
||||
- (void)recoverMicroAndVoiceWithBroadcast:(BOOL)isBroadcast;
|
||||
@end
|
||||
|
||||
204
YuMi/Tools/CardManager/XPSkillCardPlayerManager.m
Normal file
204
YuMi/Tools/CardManager/XPSkillCardPlayerManager.m
Normal file
@@ -0,0 +1,204 @@
|
||||
//
|
||||
// XPSkillCardPlayerManager.m
|
||||
// YuMi
|
||||
//
|
||||
// Created by GreenLand on 2022/3/9.
|
||||
//
|
||||
|
||||
#import "XPSkillCardPlayerManager.h"
|
||||
#import "XPRoomMiniManager.h"
|
||||
#import "RtcManager.h"
|
||||
#import "XPGiftPresenter.h"
|
||||
|
||||
@interface XPSkillCardPlayerManager()<AVAudioPlayerDelegate>
|
||||
|
||||
///是否关闭了声音、麦克风
|
||||
@property (nonatomic, assign) BOOL isCloseMuteAndMicro;
|
||||
///记录当前房间的听筒是否开启
|
||||
@property (nonatomic, assign) BOOL isMute;
|
||||
///记录当前房间是否关闭麦克风
|
||||
@property (nonatomic, assign) BOOL isCloseMicro;
|
||||
///
|
||||
@property (nonatomic,assign) BOOL isBroadcast;
|
||||
|
||||
///播放完成回调
|
||||
@property (nonatomic, copy) void (^playerCompletionBlock)(void);
|
||||
|
||||
@property (nonatomic,
|
||||
copy) NSArray <BravoGiftTabInfomationModel *>*bravoGiftInfomations;
|
||||
|
||||
@end
|
||||
|
||||
@implementation XPSkillCardPlayerManager
|
||||
|
||||
+ (instancetype)shareInstance {
|
||||
static dispatch_once_t once;
|
||||
static XPSkillCardPlayerManager *sharedInstance;
|
||||
dispatch_once(&once, ^{
|
||||
if (sharedInstance == NULL) {
|
||||
sharedInstance = [[self alloc] init];
|
||||
[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
|
||||
[[AVAudioSession sharedInstance]setActive:YES error:nil];
|
||||
}
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (void)requestBravoGiftTabInfomation {
|
||||
@kWeakify(self);
|
||||
XPGiftPresenter *presenter = [[XPGiftPresenter alloc] init];
|
||||
[presenter bravoGetBannerList:^(NSArray<BravoGiftTabInfomationModel *> * _Nonnull array) {
|
||||
@kStrongify(self);
|
||||
self.bravoGiftInfomations = array;
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSArray <BravoGiftTabInfomationModel*>*)loadBravoGiftTabInfomation {
|
||||
return self.bravoGiftInfomations;
|
||||
}
|
||||
|
||||
- (void)setMicState:(MICState)micState {
|
||||
_micState = micState;
|
||||
}
|
||||
|
||||
- (void)playerVoiceWithPath:(NSString *)filePath completionBlock:(void (^)(void))completionBlock{
|
||||
[self playerMusicWithPath:filePath volume:1 loop:NO completionBlock:completionBlock];
|
||||
}
|
||||
- (void)playerNewVoiceWithPath:(NSString *)filePath completionBlock:(void (^)(void))completionBlock{
|
||||
[self playerNewMusicWithPath:filePath volume:1 loop:NO completionBlock:completionBlock];
|
||||
}
|
||||
/**
|
||||
播放音频
|
||||
|
||||
@param filePath 本地路径
|
||||
@param volume 声音大小
|
||||
@param loop 是否循环播放
|
||||
@param completionBlock 播放完成回调
|
||||
*/
|
||||
- (void)playerMusicWithPath:(NSString *)filePath volume:(CGFloat)volume loop:(BOOL)loop completionBlock:(void (^)(void))completionBlock {
|
||||
[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
|
||||
[self closeMicroAndVoiceWithBroadcast:YES];
|
||||
if (self.player) {
|
||||
[self.player stop];
|
||||
self.player = nil;
|
||||
}
|
||||
NSLog(@"播放动画的路径:%@", filePath);
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) return;
|
||||
NSURL *url = [NSURL fileURLWithPath:filePath];
|
||||
NSError *AVerror = NULL;
|
||||
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&AVerror];
|
||||
self.player.numberOfLoops = loop ? -1 : 0;
|
||||
self.player.volume = volume;
|
||||
if (AVerror) {//无效链接
|
||||
if (completionBlock) {
|
||||
completionBlock();
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.isPlay = YES;
|
||||
self.player.delegate = self;
|
||||
[self.player prepareToPlay];
|
||||
[self.player play];
|
||||
self.playerCompletionBlock = completionBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
新的播放音频
|
||||
|
||||
@param filePath 本地路径
|
||||
@param volume 声音大小
|
||||
@param loop 是否循环播放
|
||||
@param completionBlock 播放完成回调
|
||||
*/
|
||||
- (void)playerNewMusicWithPath:(NSString *)filePath volume:(CGFloat)volume loop:(BOOL)loop completionBlock:(void (^)(void))completionBlock {
|
||||
[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
|
||||
[self closeMicroAndVoiceWithBroadcast:YES];
|
||||
|
||||
|
||||
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC));
|
||||
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
||||
if (self.player) {
|
||||
[self.player stop];
|
||||
self.player = nil;
|
||||
}
|
||||
NSLog(@"播放动画的路径:%@", filePath);
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) return;
|
||||
NSURL *url = [NSURL fileURLWithPath:filePath];
|
||||
NSError *AVerror = NULL;
|
||||
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&AVerror];
|
||||
self.player.numberOfLoops = loop ? -1 : 0;
|
||||
self.player.volume = volume;
|
||||
if (AVerror) {//无效链接
|
||||
if (completionBlock) {
|
||||
completionBlock();
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.isPlay = YES;
|
||||
self.player.delegate = self;
|
||||
[self.player prepareToPlay];
|
||||
[self.player play];
|
||||
self.playerCompletionBlock = completionBlock;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)stopMusic {
|
||||
[self stopMusicIsNeedCompletion:NO];
|
||||
}
|
||||
|
||||
- (void)stopMusicIsNeedCompletion:(BOOL)isNeedCompletion {
|
||||
if (self.player) {
|
||||
[self.player stop];
|
||||
self.player = nil;
|
||||
if (isNeedCompletion && self.playerCompletionBlock) {
|
||||
self.playerCompletionBlock();
|
||||
}
|
||||
self.playerCompletionBlock = nil;
|
||||
}
|
||||
self.isPlay = NO;
|
||||
self.volume = 1;
|
||||
[self recoverMicroAndVoiceWithBroadcast:YES];
|
||||
}
|
||||
|
||||
///关闭麦克风、听筒
|
||||
- (void)closeMicroAndVoiceWithBroadcast:(BOOL)isBroadcast{
|
||||
if (([XPSkillCardPlayerManager shareInstance].isInRoom == YES || [XPRoomMiniManager shareManager].getRoomInfo) && !self.isCloseMuteAndMicro) {
|
||||
self.isMute = [RtcManager instance].isLocalMuted;
|
||||
self.isCloseMicro = [RtcManager instance].isRemoteMuted;
|
||||
|
||||
[[RtcManager instance] setLocalMuted:YES];
|
||||
[[RtcManager instance] setRemoteMuted:YES];
|
||||
if(isBroadcast == YES){
|
||||
self.isBroadcast = [RtcManager instance].broadcast;
|
||||
[[RtcManager instance]broadcast:NO];
|
||||
}
|
||||
|
||||
self.isCloseMuteAndMicro = YES;
|
||||
}
|
||||
}
|
||||
|
||||
///恢复之前的 麦克风、听筒听筒状态
|
||||
- (void)recoverMicroAndVoiceWithBroadcast:(BOOL)isBroadcast {
|
||||
if (([XPSkillCardPlayerManager shareInstance].isInRoom == YES || [XPRoomMiniManager shareManager].getRoomInfo) && self.isCloseMuteAndMicro) {
|
||||
[[RtcManager instance] setLocalMuted:self.isMute];
|
||||
[[RtcManager instance] setRemoteMuted:self.isCloseMicro];
|
||||
if(isBroadcast == YES){
|
||||
[[RtcManager instance] broadcast:self.isBroadcast];
|
||||
}
|
||||
self.isCloseMuteAndMicro = NO;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - AVAudioPlayerDelegate
|
||||
///播放完成回调
|
||||
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
|
||||
if (self.playerCompletionBlock) {
|
||||
self.playerCompletionBlock();
|
||||
self.playerCompletionBlock = nil;
|
||||
self.isPlay = NO;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user