Skip to content

Commit

Permalink
feat(Demo): add sample code of CicadaAudioSessionDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
skufly authored and pingkai committed Apr 30, 2020
1 parent 0d8b537 commit 02cf374
Showing 1 changed file with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#import "CicadaErrorModel+string.h"
#import "AFNetworking.h"

@interface CicadaPlayerViewController ()<CicadaDemoViewDelegate,CicadaSettingAndConfigViewDelegate,CicadaDelegate>
@interface CicadaPlayerViewController ()<CicadaDemoViewDelegate,CicadaSettingAndConfigViewDelegate,CicadaDelegate,CicadaAudioSessionDelegate>

/**
播放视图
Expand Down Expand Up @@ -70,6 +70,11 @@ @interface CicadaPlayerViewController ()<CicadaDemoViewDelegate,CicadaSettingAnd
*/
@property (nonatomic,assign)BOOL needStop;

/**
混音播放
*/
@property (nonatomic,assign)BOOL enableMix;

@end

@implementation CicadaPlayerViewController
Expand Down Expand Up @@ -97,7 +102,8 @@ - (void)viewDidLoad {
[self.settingAndConfigView setIshardwareDecoder:[CicadaTool isHardware]];
[self.settingAndConfigView setConfigArray:configArray];
[self.view addSubview:self.settingAndConfigView];


[CicadaPlayer setAudioSessionDelegate:self];
self.player = [[CicadaPlayer alloc] init];
self.player.enableHardwareDecoder = [CicadaTool isHardware];
self.player.playerView = self.CicadaView.playerView;
Expand Down Expand Up @@ -163,6 +169,7 @@ - (void)viewDidDisappear:(BOOL)animated {
}
[self.player stop];
[self.player destroy];
[CicadaPlayer setAudioSessionDelegate:nil];
[self setScreenCanRotation:NO];
}

Expand Down Expand Up @@ -762,11 +769,31 @@ - (void)onLoadingProgress:(CicadaPlayer*)player progress:(float)progress {
[self.CicadaView setLoadingViewProgress:(int)progress];
}

@end



- (BOOL)setActive:(BOOL)active error:(NSError **)outError
{
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
return [[AVAudioSession sharedInstance] setActive:active error:outError];
}

- (BOOL)setCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError **)outError
{
// self.enableMix = YES;
if (self.enableMix) {
options = AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDuckOthers;
}
return [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:outError];
}

- (BOOL)setCategory:(AVAudioSessionCategory)category mode:(AVAudioSessionMode)mode routeSharingPolicy:(AVAudioSessionRouteSharingPolicy)policy options:(AVAudioSessionCategoryOptions)options error:(NSError **)outError
{
if (self.enableMix) {
return YES;
}

if (@available(iOS 11.0, tvOS 11.0, *)) {
return [[AVAudioSession sharedInstance] setCategory:category mode:mode routeSharingPolicy:policy options:options error:outError];
}
return NO;
}

@end

0 comments on commit 02cf374

Please sign in to comment.