AVAudioSession学习记录

一、枚举(enum):

   1. AVAudioSessionInterruptionOptions:只有一个枚举值AVAudioSessionInterruptionOptionShouldResume,用于中断音频之后,重新激活之前播放的音频。在音频中断时,系统会发送AVAudioSessionInterruptionNotification通知,userInfo中AVAudioSessionInterruptionTypeKeyAVAudioSessionInterruptionTypeKeyEnded时,表明中断结束,再获取userInfo中AVAudioSessionInterruptionOptions值为AVAudioSessionInterruptionOptionShouldResume,表明可以重新激活音频,并进行相应的处理。

2.AVAudioSessionSetActiveOptions只有一个枚举值AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation,用于setActive:withOptions:error:方法的Options参数中,当前App音频结束不再处于活跃状态时,通知系统将之前中断的音频(如music app),重新激活。

3.AVAudioSessionPortOverride枚举值AVAudioSessionPortOverrideNoneAVAudioSessionPortOverrideSpeaker。用于设置当前音频输出端口,None,不覆盖输出端口,使用当前默认的音频类别的端口;Speaker,覆盖当前端口,将音频输出端口转换到扬声器,仅适用于AVAudioSessionCategoryPlayAndRecord类别。

4.AVAudioSessionRouteChangeReason

枚举值:

AVAudioSessionRouteChangeReasonUnknown

AVAudioSessionRouteChangeReasonNewDeviceAvailable(如耳机插入)

AVAudioSessionRouteChangeReasonOldDeviceUnavailable(如耳机拔出)

AVAudioSessionRouteChangeReasonCategoryChange(如类别变化,AVAudioSessionCategoryPlayback改成AVAudioSessionCategoryPlayAndRecord

AVAudioSessionRouteChangeReasonOverride

AVAudioSessionRouteChangeReasonWakeFromSleep

AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory

AVAudioSessionRouteChangeReasonRouteConfigurationChange

多用于监听(AVAudioSessionRouteChangeNotification)耳机等设备变化之后,是否暂停播放音频。

5.AVAudioSessionCategoryOptions

枚举值:

AVAudioSessionCategoryOptionMixWithOthers(当你的audio session活跃时,允许混合其他应用音频。典型场景:a. 在 AVAudioSessionCategoryPlayAndRecord or AVAudioSessionCategoryMultiRoute 类别下设置,表示audio的输入输出都enabled下允许其他应用在后台播放;b. 在 AVAudioSessionCategoryPlayback 类别下设置,表示允许其他应用后台播放,但是无论如何切换 静音/铃声 都会一直播放;c. 在其他类别下设置无效

AVAudioSessionCategoryOptionDuckOthers(当你的audio session活跃时,会混合其他应用的音频,但是会降低其他音频的音量,直到你的audio session不活跃。仅在AVAudioSessionCategoryPlayAndRecord、AVAudioSessionCategoryPlayback、AVAudioSessionCategoryMultiRoute、AVAudioSessionCategoryAmbient类别下有效

AVAudioSessionCategoryOptionAllowBluetooth(可接入蓝牙设备。a. 在AVAudioSessionCategoryPlayAndRecord类别下,当用合适的输出设备播放时,可用配对的蓝牙设备进行输入;b.AVAudioSessionCategoryRecord类别下,可用配对的蓝牙设备进行输入;c.在其他类别下设置无效

AVAudioSessionCategoryOptionDefaultToSpeaker(只在AVAudioSessionCategoryPlayAndRecord类别下有效,设置扬声器播放

AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers(当你的app是导航类或者运动类应用,偶然说句提示语,仅在AVAudioSessionCategoryPlayAndRecord、AVAudioSessionCategoryPlayback、AVAudioSessionCategoryMultiRoute类别下有效

AVAudioSessionCategoryOptionAllowBluetoothA2DP(可接入蓝牙设备。a. 在AVAudioSessionCategoryPlayAndRecord类别下,当用合适的输入设备录制时,可用配对的蓝牙设备进行输出;b.在AVAudioSessionCategoryMultiRoute orAVAudioSessionCategoryRecord类别下,不能被设置;c. 在其他类别下默认设置为true且不能更改

AVAudioSessionCategoryOptionAllowAirPlay(只在AVAudioSessionCategoryPlayAndRecord类别下有效

用于setCategory:withOptions:error:方法中,设置options选项。


6.AVAudioSessionInterruptionType:枚举值AVAudioSessionInterruptionTypeBeganAVAudioSessionInterruptionTypeEnded,表示中断类型,用于判断中断开始或者结束。用AVAudioSessionInterruptionNotification进行通知。


7.AVAudioSessionSilenceSecondaryAudioHintType:枚举值AVAudioSessionSilenceSecondaryAudioHintTypeBeginAVAudioSessionSilenceSecondaryAudioHintTypeEnd,表示其他应用开始占据session,用AVAudioSessionSilenceSecondaryAudioHintNotification进行通知。


8.AVAudioSessionRecordPermission

枚举值:

AVAudioSessionRecordPermissionUndetermined(用户未确定是否授权)

AVAudioSessionRecordPermissionDenied(用户明确拒绝授权)

AVAudioSessionRecordPermissionGranted(用户明确授权)

用来判断用户是否授权录制权限。


9.AVAudioSessionIOType:枚举值AVAudioSessionIOTypeNotSpecifiedAVAudioSessionIOTypeAggregated,用于setAggregatedIOPreference:error:方法。


10.AVAudioSessionRouteSharingPolicy

枚举值:

AVAudioSessionRouteSharingPolicyDefault

AVAudioSessionRouteSharingPolicyLongForm

AVAudioSessionRouteSharingPolicyIndependent





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AVAudioSession是iOS中用于管理应用程序的音频会话的类。它允许应用程序控制和配置音频功能,如音频输入、输出、音频路由、音频处理等。AVAudioSession的目的是提供一个统一的接口,以便应用程序可以与设备的音频系统进行交互,无论是播放音乐、录制语音还是进行VoIP通话。 AVAudioSession有几个重要的概念和属性: 1. Category(分类):用于描述应用程序对音频的使用情况,如播放音乐、录制音频、播放通话等。不同的分类具有不同的优先级和行为。应用程序可以根据需要选择适当的分类,并在需要时进行切换。 2. Mode(模式):用于描述音频会话的详细行为。不同的模式针对不同的应用场景进行了优化,如游戏、音乐播放、通话等。应用程序可以根据需要设置适当的模式。 3. Route(路由):描述音频信号的路径,如扬声器、听筒、耳机等。应用程序可以查询当前的音频路由,并根据需要进行调整。 4. Options(选项):用于配置音频会话的其他参数,如混音、静音、中断处理等。 AVAudioSession还提供了一些其他的功能和方法,如设置音频输入、输出的硬件设备、监测耳机插拔事件、处理音频会话的中断和恢复等。 总之,AVAudioSession是一个强大的音频管理类,允许应用程序轻松控制和配置音频功能,并为各种应用场景提供了灵活的接口。通过使用AVAudioSession,开发者可以实现各种复杂的音频操作,提供优质的音频体验给用户。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值