AudioSession property 详解及使用方法,包括检测是否有声音正在运行,音量更改等。...


Posted on  2011年09月3日


enum { // typedef UInt32 AudioSessionPropertyID
kAudioSessionProperty_PreferredHardwareSampleRate = 'hwsr', // Float64 (get/set)
kAudioSessionProperty_PreferredHardwareIOBufferDuration = 'iobd', // Float32 (get/set)
kAudioSessionProperty_AudioCategory = 'acat', // UInt32 (get/set)
kAudioSessionProperty_AudioRoute = 'rout', // CFStringRef (get only)
kAudioSessionProperty_AudioRouteChange = 'roch', // CFDictionaryRef (property listener)
kAudioSessionProperty_CurrentHardwareSampleRate = 'chsr', // Float64 (get only)
kAudioSessionProperty_CurrentHardwareInputNumberChannels = 'chic', // UInt32 (get only)
kAudioSessionProperty_CurrentHardwareOutputNumberChannels = 'choc', // UInt32 (get only)
kAudioSessionProperty_CurrentHardwareOutputVolume = 'chov', // Float32 (get only/property listener)
kAudioSessionProperty_CurrentHardwareInputLatency = 'cilt', // Float32 (get only)
kAudioSessionProperty_CurrentHardwareOutputLatency = 'colt', // Float32 (get only)
kAudioSessionProperty_CurrentHardwareIOBufferDuration = 'chbd', // Float32 (get only)
kAudioSessionProperty_OtherAudioIsPlaying = 'othr', // UInt32 (get only)
kAudioSessionProperty_OverrideAudioRoute = 'ovrd', // UInt32 (set only)
kAudioSessionProperty_AudioInputAvailable = 'aiav', // UInt32 (get only/property listener)
kAudioSessionProperty_ServerDied = 'died', // UInt32 (property listener)
kAudioSessionProperty_OtherMixableAudioShouldDuck = 'duck', // UInt32 (get/set)
kAudioSessionProperty_OverrideCategoryMixWithOthers = 'cmix', // UInt32 (get, some set)
kAudioSessionProperty_OverrideCategoryDefaultToSpeaker = 'cspk', // UInt32 (get, some set)
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput = 'cblu', // UInt32 (get, some set)
kAudioSessionProperty_InterruptionType = 'type', // UInt32 (get only)
};

//具体作用如果字面不理解可以查看AudioServices.h(相关设置值,返回值头文件中也有)

listener使用:
AudioSessionInitialize (NULL, NULL, NULL, NULL);//初始化
OSStatus state = AudioSessionAddPropertyListener(
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,self);
//state返回值如下
enum
{
kAudioSessionNoError = 0,
kAudioSessionNotInitialized = '!ini',
kAudioSessionAlreadyInitialized = 'init',
kAudioSessionInitializationError = 'ini?',
kAudioSessionUnsupportedPropertyError = 'pty?',
kAudioSessionBadPropertySizeError = '!siz',
kAudioSessionNotActiveError = '!act',
kAudioServicesNoHardwareError = 'nohw',
kAudioSessionNoCategorySet = '?cat',
kAudioSessionIncompatibleCategory = '!cat',
kAudioSessionUnspecifiedError = 'what'
};

//get的使用
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
CFStringRef state = nil;
AudioSessionGetProperty(
kAudioSessionProperty_AudioRoute,
&propertySize,&state);

//set的使用
UInt32 propertySize = sizeof(UInt32);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 state = (1);
AudioSessionSetProperty(
kAudioSessionProperty_OtherMixableAudioShouldDuck,
propertySize,&state);


Posted in iPadiPhoneStudy Notes技巧 Tagged iPhoneobjc开发 Leave a reply
Sep 03

检测iphone插入/拔出耳机事件

Posted on  2011年09月3日


void audioRouteChangeListenerCallback (
void *inUserData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void *inData)
{
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
CFStringRef state = nil;
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute
,&propertySize,&state);

NSLog(@"%@",(NSString *)state);//return @"Headphone" or @"Speaker" and so on.
}
- (void)viewDidLoad {
[super viewDidLoad];

AudioSessionInitialize (NULL, NULL, NULL, NULL);
OSStatus status = AudioSessionAddPropertyListener(
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,self);
//if(status == 0){//ok;}
}

转载于:https://my.oschina.net/u/1049180/blog/136460

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值