
- 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
205 lines
6.9 KiB
Objective-C
205 lines
6.9 KiB
Objective-C
//
|
|
// 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
|