iOS: Deprecation of AudioSessionInitialize and AudioSessionSetProperty

淺唱寂寞╮ 提交于 2019-12-03 07:21:59
foundry

As you have observed, pretty much all of the old Core Audio AudioSession functions have been deprecated in favour of AVAudioSession.

The AVAudioSession is a singleton object which will get initialised when you first call it:

[AVAudioSession sharedInstance]

There is no separate initialize method. But you will want to activate the audio session:

BOOL activated = [[AVAudioSession sharedInstance] setActive:YES error:&error];

As regards setting the hardware sample rate using AVAudioSession, please refer to my answer here:
How can I obtain the native (hardware-supported) audio sampling rates in order to avoid internal sample rate conversion?

For other compares & contrasts between Core Audio audioSession and AVFoundation's AVAudioSession here are some of my other answers around the same topic:

How Do I Route Audio to Speaker without using AudioSessionSetProperty?

use rear microphone of iphone 5

Play audio through upper (phone call) speaker

How to control hardware mic input gain/level on iPhone?

I wrote a short tutorial that discusses how to update to the new AVAudioSession objects. I posted it on GitHub: "Replacing C functions deprecated in iOS 7."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!