Framework : AudioToolbox.framework
#import <AudioToolbox/AudioToolbox.h>
//------------------------------------------------------------------------------
// audio session Callback 함수. 출력 경로변경
//------------------------------------------------------------------------------
static void callbackFunction_audioRouteChangeListener(void* inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void* inPropertyValue)
{
if(inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
// 사운드 출력 경로가 바뀐 이유.
CFDictionaryRef routeChangeDictionary = inPropertyValue;
CFNumberRef routeChangeReasonRef = CFDictionaryGetValue(routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
SInt32 routeChangeReason;
CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
// 이어폰 뺐을때...
if(routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
{
VTMainView* mainView = inUserData;
mainView->bSpeakerMode = false;
[mainView audioSession_SpeakerOnOrOff];
}
// 이어폰 연결했을때...
if(routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable)
{
VTMainView* mainView = inUserData;
mainView->bSpeakerMode = false;
}
}
#pragma mark - AudioSession 제어 함수들...
//------------------------------------------------------------------------------
// audio session 초기화
//------------------------------------------------------------------------------
- (void)audioSession_Init
{
void* userData = self;
AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionPropertyID routeChangeID = kAudioSessionProperty_AudioRouteChange;
AudioSessionAddPropertyListener(routeChangeID, callbackFunction_audioRouteChangeListener, userData);
}
//------------------------------------------------------------------------------
// 스피커 활성화 (1:활성 0:비활성)
//------------------------------------------------------------------------------
- (void)audioSession_SpeakerOnOrOff
{
// 이미 스피커모드이면... 스피커 비활성화
if(bSpeakerMode)
{
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
}
// 스피커모드가 아니면... 스피커 활성화
else
{
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
}
bSpeakerMode = !bSpeakerMode;
}
반응형
'iOS 초보' 카테고리의 다른 글
ios 화면크기, 해상도 (0) | 2014.07.02 |
---|---|
xcode, debuging tab (0) | 2014.07.02 |
맥. proxy 서버 사용하기 (0) | 2014.07.02 |
맥, boost (0) | 2014.07.02 |
웹페이지 읽어오기 (0) | 2014.07.02 |