The sound is turned off when the player is playing the movie due to the information flow of the wide-point passband video. The specific error is reported as follows

[avas] AVAudioSession.mm:1080:-[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.  
Copy the code

SetActive is set to NO after a video is played, and the sound cannot be output.

Specific solutions:

  • XCAudioSession creates a class for AVAudioSession, overwrites this method in the class, intercepts this setting, and returns either YES or NO. By default, AVAudioSession is enabled

Link: www.jianshu.com/p/507a39b83…

-(BOOL)setActive:(BOOL)active withOptions:(AVAudioSessionSetActiveOptions)options error:(NSError*_Nullable__autoreleasing*)outError {
    return YES; 
}
Copy the code
  • Create the classification of the AVAudioSession XCAudioSession, hook setActive: withOptions: error: method, and then determine whether there is page, if in the active set to YES, if not in, depending on the Settings. This method controls active as required.

Link: www.jianshu.com/p/139907140…

+ (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class class = [self class]; SEL originalSEL = @selector(setActive:withOptions:error:); SEL swizzledSEL = @selector(xc_setActive:withOptions:error:); Method originalMethod = class_getInstanceMethod(class, originalSEL); Method swizzledMethod = class_getInstanceMethod(class, swizzledSEL); BOOL didAddMethod = class_addMethod(class, originalSEL , method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (didAddMethod) { class_replaceMethod(class, swizzledSEL, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); } else { method_exchangeImplementations(originalMethod, swizzledMethod); }}); } - (BOOL)xc_setActive:(BOOL)active withOptions:(AVAudioSessionSetActiveOptions)options error:(NSError * _Nullable __autoreleasing *)outError { BOOL customActive = [XCPlayerManager shareInstance].isPlayView ? YES : active; return [self xc_setActive:customActive withOptions:options error:outError]; }Copy the code

Note: The official Settings are as follows:

The audio Settings

Wide click-through SDK default Settings: category for AVAudioSessionCategoryAmbient, options for AVAudioSessionCategoryOptionDuckOthers

Whether to use the category and options set by AVAudioSession in SDK during audio playback. By default, the category and options set by AVAudioSession in SDK are used. If not, SDK does not do any processing.

#import "GDTSDKConfig.h"

+ (void)enableDefaultAudioSessionSetting:(BOOL)enabled;