12345678910111213141516171819202122232425262728293031323334353637 |
- //
- // AVAudioSession+RQExtension.m
- // SDJK
- //
- // Created by 张嵘 on 2021/11/26.
- //
- #import "AVAudioSession+RQExtension.h"
- #import <objc/runtime.h>
- @implementation AVAudioSession (RQExtension)
- + (void)load {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- Class class = [self class];
-
- SEL originalSEL = @selector(setActive:withOptions:error:);
- SEL swizzledSEL = @selector(lby_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)lby_setActive:(BOOL)active withOptions:(AVAudioSessionSetActiveOptions)options error:(NSError * _Nullable __autoreleasing *)outError {
- BOOL realActive = RQ_Video_Module.playerController.isPlaying ? YES : active;
- return [self lby_setActive:realActive withOptions:options error:outError];
- }
- @end
|