博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AudioSession property 详解及使用方法,包括检测是否有声音正在运行,音量更改等。...
阅读量:6952 次
发布时间:2019-06-27

本文共 3672 字,大约阅读时间需要 12 分钟。

hot3.png

Posted on 

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 , , , 
Tagged , , 
Sep
03

Posted on 

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

你可能感兴趣的文章
IO多路复用, 基于IO多路复用+socket实现并发请求(一个线程100个请求), 协程
查看>>
大白话Vue源码系列(03):生成AST
查看>>
Android 微信第三方登录
查看>>
Java中保留小数点后几位
查看>>
利用 Python_tkinter 完成 2048 游戏
查看>>
洛谷P2756 飞行员配对方案问题
查看>>
vsftpd安装
查看>>
DataSet
查看>>
Python之路【第零篇】:目录篇
查看>>
so加载报错:dlopen failed: couldn't map ... Permission denied
查看>>
LCA(st算法)
查看>>
常去的网站与常用的软件
查看>>
StyleCop 官网
查看>>
UOJ131 [NOI2015] 品酒大会
查看>>
第三章 CLR如何解析引用类型
查看>>
转:Redis监控工具—Redis-stat、RedisLive
查看>>
[LintCode] 通配符查询
查看>>
Excel,2010,可以独立打开窗口
查看>>
BZOJ3238:[AHOI2013]差异——题解
查看>>
DOIS 2019 DevOps国际峰会北京站来袭~
查看>>