BBASMAudioFocusAdapterProtocol.h 2.63 KB
//
//  BBASMAudioFocusAdapterProtocol.h
//  BBAMNP
//
//  Created by baidu on 2019/8/21.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, BBASMAppType) {
    BBASMAppTypeSMWorkBox,                        // 小程序
    BBASMAppTypeGame,                            // 小游戏
    BBASMAppTypeUnKnown                          // 未知
};

typedef NS_OPTIONS(NSUInteger, BBASMAudioFocusStreamType) {
    BBASMAudioFocusStreamTypeNone = 0,
    BBASMAudioFocusStreamTypeInput = 1 << 1,
    BBASMAudioFocusStreamTypeOutput = 1 << 2,
    BBASMAudioFocusStreamTypeInputAndOutput = (BBASMAudioFocusStreamTypeInput | BBASMAudioFocusStreamTypeOutput),
    
    BBASMAudioFocusStreamTypeOutputOptionUsingSingletonTTSPlayer __attribute__((deprecated("当前TTSPlayer为单例播放器,严重依赖业务层通知去打断,后续优化"))) = 1 << 3,
};

typedef NS_ENUM(NSInteger, BBASMAudioFocusGainType) {
    // Used to indicate a request of audio focus, of unknown duration.
    BBASMAudioFocusGain = 1,
    
    // Used to indicate a temporary gain or request of audio focus, anticipated to last a short amount of time. Examples of temporary changes are the playback of driving directions, or an event notification.
    BBASMAudioFocusGainTransient = 2,
};

typedef NS_ENUM(NSUInteger, BBASMAudioFocusRequestResult) {
    // A successful focus change request.
    BBASMAudioFocusRequestGranted,
    
    // A failed focus change request.
    BBASMAudioFocusRequestFailed,
    
    // A focus change request whose granting is delayed: the request was successful, but the requester will only be granted audio focus once the condition that prevented immediate granting has ended.
    BBASMAudioFocusRequestDelayed,
};

/**
 * private(手百私有方法):小程序使用手百音乐插件及音频统一管理
 */
@protocol BBASMAudioFocusAdapterProtocol <NSObject>

#pragma mark - AudioFocus
+ (instancetype)sharedInstance;

/**
 * @brief 申请AudioFocus
 *
 * @param focusGain focusGainType
 * @param streamType streamType
 * @param appType appType
 * @param audioFocusLossedBlock 音频焦点变化回调
 * @return 申请成功与否
 */
- (BBASMAudioFocusRequestResult)requestAudioFocusWithFocusGainType:(BBASMAudioFocusGainType)focusGain
                                                        streamType:(BBASMAudioFocusStreamType)streamType
                                                           appType:(BBASMAppType)appType
                                             audioFocusLossedBlock:(void (^)(BOOL focusLossed))audioFocusLossedBlock;

/**
 * @brief 移除AudioFocus
 */
- (void)abandonAudioFocus;

@end

NS_ASSUME_NONNULL_END