ios中同时录音和播放

 

 

 

SetRecordPlayAtSameTime_Func

 

 

 

// 需添加: AudioToolBox.framework
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#import <AudioToolbox/AudioToolbox.h>

// 设置录音和播放同时进行、且扬声器播放
-(void)SetRecordPlayAtSameTime_Func
{
    // 同时录音和播放
    UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
    
    // 扬声器播放
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
    
    AudioSessionSetActive(true);
    
    /*
    AVAudioSession* session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    [session setActive: YES error:nil];
     */
}
 
  
 
 

详细页面:http://www.verydemo.com/demo_c134_i44374.html

你可能感兴趣的:(ios)